随笔分类 -  LintCode Solutions

Solutions to problems on http://www.lintcode.com/zh-cn/problem/.
摘要:1 /** 2 * class VersionControl { 3 * public: 4 * static bool isBadVersion(int k); 5 * } 6 * you can use VersionControl::isBadVersion(k) ... 阅读全文
posted @ 2015-08-28 10:34 jianchao-li 阅读(308) 评论(0) 推荐(0) 编辑
摘要:1 class Solution { 2 public: 3 /** 4 * @param nums: a vector of integers 5 * @return: an integer 6 */ 7 int findMissing(ve... 阅读全文
posted @ 2015-07-11 21:32 jianchao-li 阅读(260) 评论(0) 推荐(0) 编辑
摘要:1 /** 2 * Definition for a point. 3 * struct Point { 4 * int x; 5 * int y; 6 * Point() : x(0), y(0) {} 7 * Point(int a, int b) ... 阅读全文
posted @ 2015-07-11 21:28 jianchao-li 阅读(1105) 评论(0) 推荐(0) 编辑
摘要:1 /** 2 * Definition of ListNode 3 * class ListNode { 4 * public: 5 * int val; 6 * ListNode *next; 7 * ListNode(int val) { 8 * ... 阅读全文
posted @ 2015-07-07 21:09 jianchao-li 阅读(211) 评论(0) 推荐(0) 编辑
摘要:1 /** 2 * Definition of ListNode 3 * class ListNode { 4 * public: 5 * int val; 6 * ListNode *next; 7 * ListNode(int val) { 8 * ... 阅读全文
posted @ 2015-07-07 20:03 jianchao-li 阅读(182) 评论(0) 推荐(0) 编辑
摘要:1 class Solution { 2 public: 3 /** 4 * @param A: a vector of integers 5 * @return: an integer 6 */ 7 int firstMissingPosit... 阅读全文
posted @ 2015-07-07 16:10 jianchao-li 阅读(256) 评论(0) 推荐(0) 编辑
摘要:递归实现: 1 class Solution { 2 public: 3 /** 4 * @param nums: A list of integers. 5 * @return: A list of unique permutations. 6 */ 7 ... 阅读全文
posted @ 2015-07-07 01:23 jianchao-li 阅读(890) 评论(0) 推荐(0) 编辑
摘要:递归实现:class Solution {public: /** * @param nums: A list of integers. * @return: A list of permutations. */ vector > permute(vector nu... 阅读全文
posted @ 2015-07-07 01:15 jianchao-li 阅读(343) 评论(0) 推荐(0) 编辑
摘要:动态规划: 1 class Solution { 2 public: 3 /** 4 * @param s: A string 5 * @param p: A string includes "?" and "*" 6 * @return: A boolean... 阅读全文
posted @ 2015-07-06 12:06 jianchao-li 阅读(219) 评论(0) 推荐(0) 编辑
摘要:1 class Solution { 2 public: 3 /** 4 * @param s: A string 5 * @param p: A string includes "." and "*" 6 * @return: A boolean 7 ... 阅读全文
posted @ 2015-07-05 23:53 jianchao-li 阅读(295) 评论(0) 推荐(0) 编辑
摘要:1 class Solution { 2 public: 3 /** 4 * @param A: An integer array. 5 * @param B: An integer array. 6 * @return: a double whose for... 阅读全文
posted @ 2015-07-03 23:33 jianchao-li 阅读(333) 评论(0) 推荐(0) 编辑
摘要:1 class Solution { 2 public: 3 /* 4 * @param n: An integer 5 * @return: True or false 6 */ 7 bool checkPowerOf2(int n) { 8 ... 阅读全文
posted @ 2015-07-01 01:59 jianchao-li 阅读(423) 评论(0) 推荐(0) 编辑
摘要:1 class Solution { 2 public: 3 /** 4 * @param dictionary: a vector of strings 5 * @return: a vector of strings 6 */ 7 vector l... 阅读全文
posted @ 2015-06-30 00:03 jianchao-li 阅读(403) 评论(0) 推荐(0) 编辑
摘要:1 class Solution { 2 public: 3 /** 4 * @param string: An array of Char 5 * @param length: The true length of the string 6 * @retur... 阅读全文
posted @ 2015-06-29 23:59 jianchao-li 阅读(374) 评论(0) 推荐(0) 编辑
摘要:暴力解法(O(mn)): 1 class Solution { 2 public: 3 /** 4 * Returns a index to the first occurrence of target in source, 5 * or -1 if target is... 阅读全文
posted @ 2015-06-29 23:23 jianchao-li 阅读(348) 评论(0) 推荐(0) 编辑
摘要:1 class Solution { 2 public: 3 /** 4 * @param A: sorted integer array A which has m elements, 5 * but size of A is m+n 6 ... 阅读全文
posted @ 2015-06-29 22:57 jianchao-li 阅读(439) 评论(0) 推荐(0) 编辑
摘要:The recursive solution is trivial and I omit it here.Iterative Solution using Stack (O(n)time andO(n)space): 1 /** 2 * Definition of TreeNode: 3 * c... 阅读全文
posted @ 2015-06-29 17:08 jianchao-li 阅读(219) 评论(0) 推荐(0) 编辑
摘要:A subroutine of merge sort. 1 class Solution { 2 public: 3 /** 4 * @param A and B: sorted integer array A and B. 5 * @return: A new sort... 阅读全文
posted @ 2015-06-29 16:44 jianchao-li 阅读(261) 评论(0) 推荐(0) 编辑
摘要:The recursive solution is trivial and I omit it here.Iterative Solution using Stack (O(n)time andO(n)space): 1 /** 2 * Definition of TreeNode: 3 * c... 阅读全文
posted @ 2015-06-29 16:21 jianchao-li 阅读(227) 评论(0) 推荐(0) 编辑
摘要:The recursive solution is trivial and I omit it here.Iterative Solution using Stack (O(n) time and O(n) space): 1 /** 2 * Definition of TreeNode: 3 ... 阅读全文
posted @ 2015-06-29 15:38 jianchao-li 阅读(306) 评论(0) 推荐(0) 编辑