随笔分类 -  lintCode

上一页 1 2 3 4 5 6 下一页

Total Occurrence of Target
摘要:public class Solution { /** * @param A an integer array sorted in ascending order * @param target an integer * @return an integer */ public int totalOccurrence(int[] A, in... 阅读全文

posted @ 2017-05-02 07:57 codingEskimo 阅读(121) 评论(0) 推荐(0)

Search a 2D Matrix
摘要:Method One: Using Binary Search Once. The point is how to calculated the number's index. mtarix[<num> / nCol][<num> % nCol] Method Two:Binary Search T 阅读全文

posted @ 2017-05-02 07:44 codingEskimo 阅读(111) 评论(0) 推荐(0)

First Position of Target
摘要:O(logN) 阅读全文

posted @ 2017-05-02 06:46 codingEskimo 阅读(117) 评论(0) 推荐(0)

Last Position of Target
摘要:O(logN)For the last element, if nums[mid] == target, we threw the first part 阅读全文

posted @ 2017-05-02 06:42 codingEskimo 阅读(159) 评论(0) 推荐(0)

Closest Number in Sorted Array
摘要:O(logN) 阅读全文

posted @ 2017-05-02 06:31 codingEskimo 阅读(143) 评论(0) 推荐(0)

Classical Binary Search
摘要:Important point: 1) While (start + 1 < end) 2) int mid = start + (end - start)/2;3) check both nums[start] and nums[end] at the end 阅读全文

posted @ 2017-05-02 06:16 codingEskimo 阅读(107) 评论(0) 推荐(0)

Course Schedule II
摘要:这是一道典型的拓扑问题。所以我们可以根据拓扑模型来完成这道题。这里面我们需要知道每个课程的入度和每个课程修完后可以解锁的课程。在这里需要注意的是因为课程从0到n-1,所以直接用index就可以做Key,不需要用到hash。这道题因为使用了入读,所以不用分级。因为入读已经帮我们把级分好。 阅读全文

posted @ 2017-03-21 12:34 codingEskimo 阅读(96) 评论(0) 推荐(0)

Graph Valid Tree
摘要:在写BFS的时候,经常会用到queue来标记需要验证的点(即由上一层而关联的各个点,就是所谓的灰色的点。黑色的点是queue最上面的那个点,就是正在被process会被poll出来那个)。然后辅助一个hash来记录是否已经visit过这个node。 阅读全文

posted @ 2017-03-17 11:45 codingEskimo 阅读(129) 评论(0) 推荐(0)

Clone Graph
摘要:Useful Links for Explanation: http://www.programcreek.com/2012/12/leetcode-clone-graph-java/ http://www.cnblogs.com/springfor/p/3874591.html 这道题可以用BFS 阅读全文

posted @ 2017-03-17 11:40 codingEskimo 阅读(92) 评论(0) 推荐(0)

Binary Tree Level Order Traversal
摘要:Very useful basic study material: http://blog.csdn.net/raphealguo/article/details/7523411 1. BFS The hard part is to define the level. Using int size 阅读全文

posted @ 2017-03-15 11:04 codingEskimo 阅读(102) 评论(0) 推荐(0)

Lowest Common Ancestor III
摘要:Analysis: 1) 左子树是不是有LCA(A,B) 2) 右子树是不是有LCA(A,B) ==> A. 有 返回LCA(A,B) B. 没有 ==> b1) 如果有遇到A或者B, 返回A或B b2)没有遇到返回null 注意;要判断AB有没有遇到。 阅读全文

posted @ 2017-03-15 07:24 codingEskimo 阅读(117) 评论(0) 推荐(0)

Validate Binary Search
摘要:这道题很简单,就是中序遍历,得到list然后valid数字排序即可 阅读全文

posted @ 2017-03-15 03:56 codingEskimo 阅读(101) 评论(0) 推荐(0)

Binary Tree Longest Consecutive Sequence
摘要:Analysis 这个结果是用Divid & Conquer 做的 1. Divid: tree->left child and right child 2. Conquer: when it is null, return 0 3. Merge:如果是sequence, 则现在的sequence的 阅读全文

posted @ 2017-03-15 02:56 codingEskimo 阅读(88) 评论(0) 推荐(0)

Binary Tree Path Sum
摘要:Analysis: 这道题不难,但是我对于数结构以及递归掌握还是不够好,无法举一反三。 这道题要求所有的path,可以想到排列组合问题,所以可以套用排列组合模板。 但是因为这个是树结构,所以在套用的时候,要左右子树各走一遍。 这道题也是树的问题,用递归的时候要考虑三要素,递归的定义,递归的拆解,递归 阅读全文

posted @ 2017-03-15 01:22 codingEskimo 阅读(138) 评论(0) 推荐(0)

[LeetCode] 104. Maximum Depth of Binary Tree
摘要:Good reference for all tree problem https://sites.google.com/site/jennyshelloworld/company-blog/chapter-3 binary-tree-divide-conquer Analysis: Here we 阅读全文

posted @ 2017-03-12 02:48 codingEskimo 阅读(104) 评论(0) 推荐(0)

[LintCode 68] Binary Tree Postorder Traversal
摘要:1. Recursive Straight Forward, left -> right -> root 2. Iterator This is a little bit hard to understand, here is good reference https://sites.google. 阅读全文

posted @ 2017-03-12 02:20 codingEskimo 阅读(96) 评论(0) 推荐(0)

Binary Tree Inorder Traversal
摘要:1. Recursive Straight Forward, Add left -> root -> right 2. Iterator 1. Create a node to present current node. 2. If current node is not null and stac 阅读全文

posted @ 2017-03-12 01:54 codingEskimo 阅读(99) 评论(0) 推荐(0)

Binary Tree Preorder Traversal
摘要:1. Recursive: Very Straight forward, If the node is not null, add root -> traversal left -> traversal right 2. Iterator(find a very good explanation h 阅读全文

posted @ 2017-03-12 01:30 codingEskimo 阅读(111) 评论(0) 推荐(0)

[LeetCode] 28. Implement strStr
摘要:Notice 1. Input String always need to be check whether it is NULL; 2. For the conner cases, source is shorter than the target or target is empty, it c 阅读全文

posted @ 2017-03-12 00:55 codingEskimo 阅读(151) 评论(0) 推荐(0)

Restore IP Address
摘要:这道题和Palindrome Partitioning很像,都是怎么切数组的问题,唯一需要注意的是ip的规定 1)不能出现0和其他数字组合, 类似0.00.01.1。0只能单独出现或者在一个片段中不为开头的数字。 2)每一个片段数字最大为255 3)只能有四个片段 4)这里需要注意一个细节: 在这里 阅读全文

posted @ 2016-08-20 04:51 codingEskimo 阅读(268) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 下一页

导航