- 浏览: 201221 次
- 性别:
- 来自: 杭州
最新评论
-
hthhit:
...
回溯算法之N皇后问题(java实现) -
huntfor:
249326109 写道这个算法的复杂度有考虑过么O(n^2) ...
[leetcode]Longest Valid Parentheses -
249326109:
这个算法的复杂度有考虑过么
[leetcode]Longest Valid Parentheses -
huntfor:
249326109 写道又搜到你的了 你怎么搜的,为啥我搜不到 ...
[leetcode]Sort Colors -
249326109:
又搜到你的了
[leetcode]Sort Colors
文章列表
这篇博文作废,新博文地址:[leetcode]Search a 2D Matrix
Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the ...
新博文地址:[leetcode]Pascal's Triangle II
Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?
求第i行的杨辉三角的值,感觉很奇怪,leetcode中对边界条件的检查貌似很无力,比如rowIndex < 0没有做出检查 ...
新博文地址:
[leetcode]N-Queens
N-Queens
写道
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each solution contains a distinct board confi ...
新博文地址:
[leetcode]Binary Tree Postorder Traversal
Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].
后序遍历,题中提示说不让用递归,让用迭代。明天再搞吧。
先给出一个递归版本:
ArrayList<Integer ...
新博文地址:
[leetcode]N-QueensII
N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.
八皇后问题,返回解的个数,比返回解的情况还要简单,这个问题之前专门写过一篇博文讲解过,不明白的细节可以看这里。
很经典的回溯算法,不多啰嗦。
int success = 0;
public int totalNQueens(int n) {
i ...
新博文地址:
[leetcode]Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal II
写道
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7}, ...
新博文地址:[leetcode]Validate Binary Search Tree
Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.The right subtree of a node contain ...
新博文地址:
[leetcode]Binary Tree Level Order Traversal
Binary Tree Level Order Traversal
写道
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 ...
新博文地址:Partition List
果然出去玩了一个星期回来状态极差。。。。
Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of the two partitions.For example,Given 1-> ...
新博文地址:[leetcode]Triangle
Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + ...
新博文地址:
[leetcode]Combination Sum
Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited number of times. Note: All numbers (including target) ...
新博文地址:[leetcode]Rotate List
Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL.
将链表翻转,我不知道OJ上怎么处理k>length的情况,我是直接取余了
public ListN ...
新博文地址:[leetcode]Simplify Path
Simplify Path
Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" click to show corner cases. Corner Cases: Did you consider the case ...
新博文地址:[leetcode]Unique Paths II
Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid. For example, There is one obstacle in the ...
新博文地址:[leetcode]Unique Paths
Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the di ...