随笔分类 -  LeetCode Solutions

上一页 1 ··· 8 9 10 11 12
Solutions to problems on https://leetcode.com/problemset/algorithms/.
摘要:This is a typical DP problem. Suppose the minimum path sum of arriving at point(i, j)isS[i][j], then the state equation isS[i][j] = min(S[i - 1][j], S... 阅读全文
posted @ 2015-06-02 23:42 jianchao-li 阅读(231) 评论(0) 推荐(0)
摘要:Well, this problem is similar toUnique Paths. The introduction of obstacles only changes the boundary conditions and make some points unreachable (sim... 阅读全文
posted @ 2015-06-02 23:41 jianchao-li 阅读(159) 评论(0) 推荐(0)
摘要:This is a fundamental DP problem. First of all, let's make some observations.Since the robot can only move right and down, when it arrives at a point,... 阅读全文
posted @ 2015-06-02 23:40 jianchao-li 阅读(215) 评论(0) 推荐(0)
摘要:Well, this problem has a naive solution, which is to sort the array in descending order and return thek-1-th element. However, sorting algorithm gives... 阅读全文
posted @ 2015-06-02 23:39 jianchao-li 阅读(375) 评论(0) 推荐(0)
摘要:Well, I do not see what this problem is for. The same code of Binary Tree Level Order Traversal can be used here. The only difference is that we shoul... 阅读全文
posted @ 2015-06-02 23:31 jianchao-li 阅读(182) 评论(0) 推荐(0)
摘要:A classic tree traversal problem. I share my two solutions here: BFS and DFS.BFS: 1 vector> levelOrder(TreeNode *root) { 2 vector> levels;... 阅读全文
posted @ 2015-06-02 23:29 jianchao-li 阅读(181) 评论(0) 推荐(0)
摘要:This is a fundamental and yet classic problem. I share my three solutions here:Iterative solution using stack ---O(n)time andO(n)space;Recursive solut... 阅读全文
posted @ 2015-06-02 23:27 jianchao-li 阅读(260) 评论(0) 推荐(0)
摘要:This is a fundamental and yet classic problem. I share my three solutions here:Iterative solution using stack ---O(n)time andO(n)space;Recursive solut... 阅读全文
posted @ 2015-06-02 23:22 jianchao-li 阅读(262) 评论(0) 推荐(0)
摘要:This is a fundamental and yet classic problem. I share my three solutions here:Iterative solution using stack ---O(n)time andO(n)space;Recursive solut... 阅读全文
posted @ 2015-06-02 23:20 jianchao-li 阅读(260) 评论(0) 推荐(0)
摘要:Well, the basic idea is fairly straightforward. We maintain a mappingmpfrom a value innumsto its position (index)i. Each time we meet an unseen value,... 阅读全文
posted @ 2015-06-02 23:18 jianchao-li 阅读(172) 评论(0) 推荐(0)
摘要:This problem is a little tricky at first glance. However, if you have finished theHouse Robber problem, this problem can simply bedecomposed into two ... 阅读全文
posted @ 2015-06-02 23:17 jianchao-li 阅读(183) 评论(0) 推荐(0)
摘要:Well, have you solved thenextPermutationproblem? If so and you have handled the cases of duplicates at that problem, your code can be used in this pro... 阅读全文
posted @ 2015-06-02 23:11 jianchao-li 阅读(235) 评论(0) 推荐(0)
摘要:Well, have you solved thenextPermutationproblem? If so, your code can be used in this problem. The idea is fairly simple:sortnumsin ascending order, a... 阅读全文
posted @ 2015-06-02 23:09 jianchao-li 阅读(259) 评论(0) 推荐(0)
摘要:Well, in fact the problem of next permutation has been studied long ago. From theWikipedia page, in the 14th century, a man named Narayana Pandita giv... 阅读全文
posted @ 2015-06-02 23:06 jianchao-li 阅读(290) 评论(0) 推荐(0)

上一页 1 ··· 8 9 10 11 12