09 2015 档案

摘要:There are mainly two solutions to solve this problem.The first one is very clever, using the idea of cycle detection, and runs in O(n) time. You may r... 阅读全文
posted @ 2015-09-28 17:26 jianchao-li 阅读(381) 评论(0) 推荐(0) 编辑
摘要:Problem Description:You are given am x n2D grid initialized with these three possible values.-1- A wall or an obstacle.0- A gate.INF- Infinity means a... 阅读全文
posted @ 2015-09-24 20:57 jianchao-li 阅读(3899) 评论(0) 推荐(1) 编辑
摘要:Problem Description:Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has no in... 阅读全文
posted @ 2015-09-22 15:59 jianchao-li 阅读(3569) 评论(0) 推荐(0) 编辑
摘要:An interesting problem about iterators. This post shares a very nice solution, which is rewritten below, with minor simplifications.// Below is the in... 阅读全文
posted @ 2015-09-21 12:18 jianchao-li 阅读(386) 评论(0) 推荐(0) 编辑
摘要:This post shares a very nice solution, which is rewritten below. 1 class Solution { 2 public: 3 vector addOperators(string num, int target) { 4 ... 阅读全文
posted @ 2015-09-16 21:58 jianchao-li 阅读(465) 评论(0) 推荐(0) 编辑
摘要:The key challenge to this problem is to make the code clean. This post has shared a nice example, which is rewritten below in C++.class Solution {publ... 阅读全文
posted @ 2015-09-14 14:53 jianchao-li 阅读(219) 评论(0) 推荐(0) 编辑
摘要:Problem Description:Given two 1d vectors, implement an iterator to return their elements alternately.For example, given two 1d vectors:v1 = [1, 2]v2 =... 阅读全文
posted @ 2015-09-14 14:16 jianchao-li 阅读(2468) 评论(0) 推荐(0) 编辑
摘要:Problem Description:Given an unsorted arraynums, reorder itin-placesuch thatnums[0] = nums[2] = nums[i - 1];Ifiis even, thennums[i] & nums) {4 ... 阅读全文
posted @ 2015-09-10 12:57 jianchao-li 阅读(2465) 评论(0) 推荐(0) 编辑
摘要:Well, after seeing the similar problems, you may have known how to solve this problem. Yeah, just to construct larger numbers from smaller numbers by ... 阅读全文
posted @ 2015-09-09 22:47 jianchao-li 阅读(602) 评论(0) 推荐(0) 编辑
摘要:This post shares a nice explanation, which is implemented here. The code is rewritten below. 1 class Solution { 2 public: 3 string minWindow(strin... 阅读全文
posted @ 2015-09-08 18:42 jianchao-li 阅读(206) 评论(0) 推荐(0) 编辑
摘要:This problem is relatively easy. The challenge is how to get a concise code. This post shares a very elegant one which traverses each cell of board on... 阅读全文
posted @ 2015-09-08 17:51 jianchao-li 阅读(226) 评论(0) 推荐(0) 编辑
摘要:Just don't be scared by this problem :-) It's also very standard backtracking problem. This post shares a very concise code, which is rewritten below ... 阅读全文
posted @ 2015-09-08 17:35 jianchao-li 阅读(219) 评论(0) 推荐(0) 编辑
摘要:Just use binary search to find the first bad version.The code is as follows. 1 // Forward declaration of isBadVersion API. 2 bool isBadVersion(int ver... 阅读全文
posted @ 2015-09-07 21:52 jianchao-li 阅读(177) 评论(0) 推荐(0) 编辑
摘要:Problem Description: Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition 阅读全文
posted @ 2015-09-06 22:43 jianchao-li 阅读(1276) 评论(0) 推荐(0) 编辑
摘要:Problem Description:There is a fence with n posts, each post can be painted with one of the k colors.You have to paint all the posts such that no more... 阅读全文
posted @ 2015-09-05 12:24 jianchao-li 阅读(4185) 评论(0) 推荐(1) 编辑
摘要:This problem is designed specifically to use binary search. In fact, in H-Index, someone has already used this idea (you may refer to this post :-))Th... 阅读全文
posted @ 2015-09-04 22:19 jianchao-li 阅读(252) 评论(0) 推荐(0) 编辑
摘要:If you've read the Wikipedia article of H-Index, there is already a neat formula there for computing the h-index, which is written below using the not... 阅读全文
posted @ 2015-09-04 22:15 jianchao-li 阅读(398) 评论(0) 推荐(0) 编辑
摘要:This link shares a nice solution with explanation using DP. You will be clear of the algorithm after running it on its suggested example:matrix = [[0,... 阅读全文
posted @ 2015-09-02 12:18 jianchao-li 阅读(217) 评论(0) 推荐(0) 编辑
摘要:The basic idea is as follows:Create anew_headthat points toheadand use it to locate the immediate node before them-th (notice that it is1-indexed) nod... 阅读全文
posted @ 2015-09-01 23:55 jianchao-li 阅读(154) 评论(0) 推荐(0) 编辑
摘要:This link has a very neat code, which is rewritten below using stacksince thepushandpopoperations of it areO(1)time, while thepop_backandpush_backofve... 阅读全文
posted @ 2015-09-01 21:20 jianchao-li 阅读(205) 评论(0) 推荐(0) 编辑