05 2014 档案

摘要:原题地址:https://oj.leetcode.com/problems/gas-station/题意:There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You ha... 阅读全文
posted @ 2014-05-30 14:20 南郭子綦 阅读(2768) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/candy/题意:There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to ... 阅读全文
posted @ 2014-05-30 13:20 南郭子綦 阅读(1679) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/word-break-ii/题意:Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each ... 阅读全文
posted @ 2014-05-30 11:53 南郭子綦 阅读(4505) 评论(1) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/word-break/题意:Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated... 阅读全文
posted @ 2014-05-30 10:53 南郭子綦 阅读(6067) 评论(1) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/max-points-on-a-line/题意:Givennpoints on a 2D plane, find the maximum number of points that lie on the same strai... 阅读全文
posted @ 2014-05-30 10:35 南郭子綦 阅读(2785) 评论(1) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/evaluate-reverse-polish-notation/题意:Evaluate the value of an arithmetic expression inReverse Polish Notation.Val... 阅读全文
posted @ 2014-05-30 09:55 南郭子綦 阅读(3078) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/reverse-words-in-a-string/题意:Given an input string, reverse the string word by word.For example,Given s = "the s... 阅读全文
posted @ 2014-05-30 09:27 南郭子綦 阅读(2918) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/median-of-two-sorted-arrays/题意:There are two sorted arrays A and B of size m and n respectively. Find the median... 阅读全文
posted @ 2014-05-29 17:34 南郭子綦 阅读(11563) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/permutations-ii/题意:Given a collection of numbers that might contain duplicates, return all possible unique permu... 阅读全文
posted @ 2014-05-29 13:05 南郭子綦 阅读(4007) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/permutations/题意:Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the foll... 阅读全文
posted @ 2014-05-29 12:17 南郭子綦 阅读(6541) 评论(0) 推荐(1) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/palindrome-partitioning-ii/题意:Given a strings, partitionssuch that every substring of the partition is a palindr... 阅读全文
posted @ 2014-05-29 11:58 南郭子綦 阅读(3274) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/palindrome-partitioning/题意:Given a strings, partitionssuch that every substring of the partition is a palindrome... 阅读全文
posted @ 2014-05-29 09:52 南郭子綦 阅读(3883) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/subsets-ii/题意:Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:E... 阅读全文
posted @ 2014-05-29 09:22 南郭子綦 阅读(3382) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/subsets/题意:枚举所有子集。解题思路:碰到这种问题,一律dfs。代码:class Solution: # @param S, a list of integer # @return a list of l... 阅读全文
posted @ 2014-05-28 15:54 南郭子綦 阅读(6075) 评论(2) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/combinations/题意:组合求解问题。解题思路:这种求组合的问题,需要使用dfs来解决。代码:class Solution: # @return a list of lists of integers d... 阅读全文
posted @ 2014-05-28 15:24 南郭子綦 阅读(4384) 评论(2) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/minimum-path-sum/题意:Given amxngrid filled with non-negative numbers, find a path from top left to bottom right w... 阅读全文
posted @ 2014-05-26 17:56 南郭子綦 阅读(2760) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/climbing-stairs/题意:You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either cl... 阅读全文
posted @ 2014-05-26 17:32 南郭子綦 阅读(4398) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/clone-graph/题意:实现对一个图的深拷贝。解题思路:由于遍历一个图有两种方式:bfs和dfs。所以深拷贝一个图也可以采用这两种方法。不管使用dfs还是bfs都需要一个哈希表map来存储原图中的节点和新图中的节点的一... 阅读全文
posted @ 2014-05-26 17:15 南郭子綦 阅读(5357) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/path-sum-ii/题意:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given... 阅读全文
posted @ 2014-05-26 10:11 南郭子綦 阅读(3287) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/path-sum/题意:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all... 阅读全文
posted @ 2014-05-26 09:56 南郭子綦 阅读(3562) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/unique-binary-search-trees-ii/题意:接上一题,这题要求返回的是所有符合条件的二叉查找树,而上一题要求的是符合条件的二叉查找树的棵数,我们上一题提过,求个数一般思路是动态规划,而枚举的话,我们就考... 阅读全文
posted @ 2014-05-26 09:39 南郭子綦 阅读(4122) 评论(1) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/unique-binary-search-trees/题意:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1... 阅读全文
posted @ 2014-05-23 15:26 南郭子綦 阅读(3612) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/n-queens-ii/题意:和N-Queens这道题其实是一样的,只不过这次要求返回的时N皇后的解的个数的问题。解题思路:上道题使用了递归回溯的解法,这道题我们可以使用非递归回溯来解决,因为如果使用递归回溯来解决,那么代码... 阅读全文
posted @ 2014-05-23 14:31 南郭子綦 阅读(1990) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/n-queens/题意:经典的N皇后问题。解题思路:这类型问题统称为递归回溯问题,也可以叫做对决策树的深度优先搜索(dfs)。N皇后问题有个技巧的关键在于棋盘的表示方法,这里使用一个数组就可以表达了。比如board=[1, ... 阅读全文
posted @ 2014-05-23 11:25 南郭子綦 阅读(4716) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/symmetric-tree/题意:判断二叉树是否为对称的。Given a binary tree, check whether it is a mirror of itself (ie, symmetric around ... 阅读全文
posted @ 2014-05-23 11:03 南郭子綦 阅读(4602) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/same-tree/题意:判断两棵树是否是同一棵树。解题思路:这题比较简单。用递归来做。首先判断两个根节点的值是否相同,如果相同,递归判断根的左右子树。代码:# Definition for a binary tree n... 阅读全文
posted @ 2014-05-23 10:51 南郭子綦 阅读(3768) 评论(0) 推荐(1) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/validate-binary-search-tree/题意:检测一颗二叉树是否是二叉查找树。解题思路:看到二叉树我们首先想到需要进行递归来解决问题。这道题递归的比较巧妙。让我们来看下面一棵树: ... 阅读全文
posted @ 2014-05-23 10:47 南郭子綦 阅读(4185) 评论(2) 推荐(1) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/recover-binary-search-tree/题意:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree... 阅读全文
posted @ 2014-05-22 22:20 南郭子綦 阅读(3449) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/binary-tree-maximum-path-sum/题意:Given a binary tree, find the maximum path sum.The path may start and end at any... 阅读全文
posted @ 2014-05-22 14:43 南郭子綦 阅读(3727) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/题意:Follow up for problem "Populating Next Right Pointers in Each ... 阅读全文
posted @ 2014-05-22 12:20 南郭子綦 阅读(1899) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node/题意: 1 / \ 2 3 / \ / \ 4 5 6 7变为: ... 阅读全文
posted @ 2014-05-22 10:52 南郭子綦 阅读(2051) 评论(0) 推荐(0) 编辑
摘要:原题地址:https://oj.leetcode.com/problems/copy-list-with-random-pointer/题意:A linked list is given such that each node contains an additional random pointe... 阅读全文
posted @ 2014-05-22 10:37 南郭子綦 阅读(7669) 评论(1) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/convert-sorted-list-to-binary-search-tree/题意:将一条排序好的链表转换为二叉查找树,二叉查找树需要平衡。解题思路:两个思路:一,可以使用快慢指针来找到中间的那个节点,然后将这个节点作为... 阅读全文
posted @ 2014-05-11 19:18 南郭子綦 阅读(3987) 评论(1) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/题意:将一个排序好的数组转换为一颗二叉查找树,这颗二叉查找树要求是平衡的。解题思路:由于要求二叉查找树是平衡的。所以我们可以选在数组的中间那... 阅读全文
posted @ 2014-05-11 19:09 南郭子綦 阅读(3031) 评论(0) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/题意:Given a binary tree, return thebottom-up level ordertraversal of its node... 阅读全文
posted @ 2014-05-11 18:44 南郭子綦 阅读(2749) 评论(0) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/minimum-depth-of-binary-tree/题意:Given a binary tree, find its minimum depth.The minimum depth is the number of no... 阅读全文
posted @ 2014-05-11 18:23 南郭子綦 阅读(3654) 评论(0) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/binary-tree-zigzag-level-order-traversal/题意:Given a binary tree, return thezigzag level ordertraversal of its nod... 阅读全文
posted @ 2014-05-11 18:05 南郭子綦 阅读(2651) 评论(0) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/binary-tree-level-order-traversal/题意:二叉树的层序遍历的实现。解题思路:二叉树的层序遍历可以用bfs或者dfs来实现。这里使用的dfs实现,代码比较简洁。实际上,二叉树的先序遍历就是dfs实... 阅读全文
posted @ 2014-05-11 17:55 南郭子綦 阅读(5018) 评论(0) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/sum-root-to-leaf-numbers/题意:Given a binary tree containing digits from0-9only, each root-to-leaf path could repre... 阅读全文
posted @ 2014-05-11 10:07 南郭子綦 阅读(2174) 评论(0) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/flatten-binary-tree-to-linked-list/题意:Given a binary tree, flatten it to a linked list in-place.For example,Given... 阅读全文
posted @ 2014-05-10 22:55 南郭子綦 阅读(3783) 评论(0) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/binary-tree-postorder-traversal/题意:实现后序遍历。递归实现比较简单,非递归实现。解题思路:这道题的迭代求解比先序遍历和后序遍历要麻烦一些。假设一棵树是这样的: ... 阅读全文
posted @ 2014-05-10 18:40 南郭子綦 阅读(3283) 评论(0) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/binary-tree-preorder-traversal/题意:这题用递归比较简单。应该考察的是使用非递归实现二叉树的先序遍历。先序遍历的遍历顺序是:根,左子树,右子树。解题思路:如果树为下图: ... 阅读全文
posted @ 2014-05-10 12:44 南郭子綦 阅读(4209) 评论(0) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/binary-tree-inorder-traversal/题意:二叉树的中序遍历。这道题用递归比较简单,考察的是非递归实现二叉树中序遍历。中序遍历顺序为:左子树,根,右子树。如此递归下去。解题思路:假设树为: ... 阅读全文
posted @ 2014-05-10 11:50 南郭子綦 阅读(4866) 评论(0) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/balanced-binary-tree/题意:判断一颗二叉树是否是平衡二叉树。解题思路:在这道题里,平衡二叉树的定义是二叉树的任意节点的两颗子树之间的高度差小于等于1。这实际上是AVL树的定义。首先要写一个计算二叉树高度的函... 阅读全文
posted @ 2014-05-10 10:54 南郭子綦 阅读(5729) 评论(0) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/题意:根据二叉树的先序遍历和中序遍历恢复二叉树。解题思路:可以参照http://www.cnblogs.com... 阅读全文
posted @ 2014-05-10 10:40 南郭子綦 阅读(2238) 评论(1) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/题意:根据二叉树的中序遍历和后序遍历恢复二叉树。解题思路:看到树首先想到要用递归来解题。以这道题为例:如果一... 阅读全文
posted @ 2014-05-10 10:34 南郭子綦 阅读(3116) 评论(2) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/single-number-ii/题意:Given an array of integers, every element appearsthreetimes except for one. Find that single ... 阅读全文
posted @ 2014-05-09 22:38 南郭子綦 阅读(4126) 评论(1) 推荐(0) 编辑
摘要:原题地址:http://www.cnblogs.com/x1957/p/3373994.html题意:Given an array of integers, every element appearstwiceexcept for one. Find that single one.要求:线性时间复... 阅读全文
posted @ 2014-05-09 20:23 南郭子綦 阅读(4635) 评论(0) 推荐(0) 编辑
摘要:原题地址:http://oj.leetcode.com/problems/valid-number/题意:判断输入的字符串是否是合法的数。解题思路:这题只能用确定有穷状态自动机(DFA)来写会比较优雅。本文参考了http://blog.csdn.net/kenden23/article/detail... 阅读全文
posted @ 2014-05-01 19:49 南郭子綦 阅读(4427) 评论(1) 推荐(4) 编辑

点击右上角即可分享
微信分享提示