摘要: The problem statement has stated that there are bothO(n)andO(nlogn)solutions to this problem. Let's see theO(n)solution first (taken fromthis link), w... 阅读全文
posted @ 2015-06-25 17:33 jianchao-li 阅读(228) 评论(0) 推荐(0) 编辑
摘要: Problem Description:Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.The input string d... 阅读全文
posted @ 2015-06-25 16:56 jianchao-li 阅读(237) 评论(0) 推荐(0) 编辑
摘要: This link has a great discussion about this problem. You may refer to it if you like. In fact, the idea and code in this passage is from the former li... 阅读全文
posted @ 2015-06-25 15:28 jianchao-li 阅读(774) 评论(0) 推荐(0) 编辑
摘要: Well, this problem has a nice BFS structure.Let's see the example in the problem statement.start = "hit"end = "cog"dict = ["hot", "dot", "dog", "lot",... 阅读全文
posted @ 2015-06-25 01:00 jianchao-li 阅读(310) 评论(0) 推荐(0) 编辑
摘要: This problem is not quite difficult (a typical BFS traversal of graph), though, its aceptance rate is relatively low. In fact, the key obstacle in pas... 阅读全文
posted @ 2015-06-24 19:09 jianchao-li 阅读(222) 评论(0) 推荐(0) 编辑
摘要: This problem is an application of graph traversal, which has two systematic methods:Bread-First Search (BFS)andDepth-First Search (DFS). In the follow... 阅读全文
posted @ 2015-06-24 16:03 jianchao-li 阅读(198) 评论(0) 推荐(0) 编辑
摘要: To solve this problem, some observations have to be made first.Let's first see two relatively easy observations.To maximize the probability that we ca... 阅读全文
posted @ 2015-06-24 00:51 jianchao-li 阅读(354) 评论(0) 推荐(0) 编辑
摘要: This is a typical problem aboutsearching. In fact, you can use either BFS or DFS for it. Personally, I use BFS because I think it is more intuitive an... 阅读全文
posted @ 2015-06-23 20:25 jianchao-li 阅读(227) 评论(0) 推荐(0) 编辑
摘要: The basic idea of is as follows:Maintain a dequeoperandsfor the numbers and another dequeoperationsfor the operators+, -, *,/`.Scan the expression fro... 阅读全文
posted @ 2015-06-22 23:27 jianchao-li 阅读(307) 评论(0) 推荐(0) 编辑
摘要: This problem can be solved elegantly using dynamic programming.We maintain two arrays:cnt[i][j] --- number of parentheses needed to add within s[i..j]... 阅读全文
posted @ 2015-06-22 17:58 jianchao-li 阅读(219) 评论(0) 推荐(0) 编辑
摘要: KMP is a classic and yet notoriously hard-to-understand algorithm. However, I think the following two links give nice explanations. You may refer to t... 阅读全文
posted @ 2015-06-19 15:25 jianchao-li 阅读(262) 评论(0) 推荐(0) 编辑
摘要: Well, a typical backtracking problem. Make sure you are clear with the following three problems:What is a partial solution and when is it finished? --... 阅读全文
posted @ 2015-06-18 00:23 jianchao-li 阅读(196) 评论(0) 推荐(0) 编辑
摘要: Well, a typical backtracking problem. Make sure you are clear with the following three problems:What is a partial solution and when is it finished? --... 阅读全文
posted @ 2015-06-16 23:57 jianchao-li 阅读(250) 评论(0) 推荐(0) 编辑
摘要: A typical backtracking problem. For any backtracking problem, you need to be think about three ascepts:What is a partial solution and when is it finis... 阅读全文
posted @ 2015-06-16 23:45 jianchao-li 阅读(178) 评论(0) 推荐(0) 编辑
摘要: The Longest Increasing Subsequence (LIS) problem requires us to find a subsequence t of a given sequence s, such that t satisfies two requirements:Ele... 阅读全文
posted @ 2015-06-15 11:46 jianchao-li 阅读(265) 评论(0) 推荐(0) 编辑