上一页 1 ··· 5 6 7 8 9 10 11 12 下一页
摘要: 原题地址: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 南郭子綦 阅读(6072) 评论(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 南郭子綦 阅读(4379) 评论(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 南郭子綦 阅读(2757) 评论(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 南郭子綦 阅读(4393) 评论(0) 推荐(0) 编辑
摘要: 原题地址:https://oj.leetcode.com/problems/clone-graph/题意:实现对一个图的深拷贝。解题思路:由于遍历一个图有两种方式:bfs和dfs。所以深拷贝一个图也可以采用这两种方法。不管使用dfs还是bfs都需要一个哈希表map来存储原图中的节点和新图中的节点的一... 阅读全文
posted @ 2014-05-26 17:15 南郭子綦 阅读(5355) 评论(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 南郭子綦 阅读(3283) 评论(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 南郭子綦 阅读(3559) 评论(0) 推荐(0) 编辑
摘要: 原题地址:https://oj.leetcode.com/problems/unique-binary-search-trees-ii/题意:接上一题,这题要求返回的是所有符合条件的二叉查找树,而上一题要求的是符合条件的二叉查找树的棵数,我们上一题提过,求个数一般思路是动态规划,而枚举的话,我们就考... 阅读全文
posted @ 2014-05-26 09:39 南郭子綦 阅读(4109) 评论(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 南郭子綦 阅读(3610) 评论(0) 推荐(0) 编辑
摘要: 原题地址:https://oj.leetcode.com/problems/n-queens-ii/题意:和N-Queens这道题其实是一样的,只不过这次要求返回的时N皇后的解的个数的问题。解题思路:上道题使用了递归回溯的解法,这道题我们可以使用非递归回溯来解决,因为如果使用递归回溯来解决,那么代码... 阅读全文
posted @ 2014-05-23 14:31 南郭子綦 阅读(1985) 评论(0) 推荐(0) 编辑
摘要: 原题地址:https://oj.leetcode.com/problems/n-queens/题意:经典的N皇后问题。解题思路:这类型问题统称为递归回溯问题,也可以叫做对决策树的深度优先搜索(dfs)。N皇后问题有个技巧的关键在于棋盘的表示方法,这里使用一个数组就可以表达了。比如board=[1, ... 阅读全文
posted @ 2014-05-23 11:25 南郭子綦 阅读(4710) 评论(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 南郭子綦 阅读(4599) 评论(0) 推荐(0) 编辑
摘要: 原题地址:https://oj.leetcode.com/problems/same-tree/题意:判断两棵树是否是同一棵树。解题思路:这题比较简单。用递归来做。首先判断两个根节点的值是否相同,如果相同,递归判断根的左右子树。代码:# Definition for a binary tree n... 阅读全文
posted @ 2014-05-23 10:51 南郭子綦 阅读(3767) 评论(0) 推荐(1) 编辑
摘要: 原题地址:https://oj.leetcode.com/problems/validate-binary-search-tree/题意:检测一颗二叉树是否是二叉查找树。解题思路:看到二叉树我们首先想到需要进行递归来解决问题。这道题递归的比较巧妙。让我们来看下面一棵树: ... 阅读全文
posted @ 2014-05-23 10:47 南郭子綦 阅读(4179) 评论(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 南郭子綦 阅读(3439) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 下一页