摘要: Well, there many ways to solve this problem. Let's first look at a naive solution.The basic idea is simple. Starting from the first character of the s... 阅读全文
posted @ 2015-06-07 21:14 jianchao-li 阅读(204) 评论(0) 推荐(0) 编辑
摘要: The key of this problem is that we need not build the tree from scratch. In fact, we can direct obtain its post-order traversal results in a recursive... 阅读全文
posted @ 2015-06-07 16:51 jianchao-li 阅读(187) 评论(0) 推荐(0) 编辑
摘要: This is a application of the Trie data structure, with minor extension. The critical part in this problem is to count all the words that have a partic... 阅读全文
posted @ 2015-06-07 16:44 jianchao-li 阅读(233) 评论(0) 推荐(0) 编辑
摘要: A direct applicatin of the heap data structure. Specifically, a max heap is used. The required functions include insertion of a node to the heap and e... 阅读全文
posted @ 2015-06-07 16:39 jianchao-li 阅读(195) 评论(0) 推荐(0) 编辑
摘要: The idea is to usetwo stacks.Forpush, the first stack records the pushed elements and the second stack recordsallthe minimum (including duplicates) th... 阅读全文
posted @ 2015-06-07 01:40 jianchao-li 阅读(193) 评论(0) 推荐(0) 编辑
摘要: This problem is an application of the Trie data structure. In the following, it is assumed that you have solvedImplement Trie (Prefix Tree).Now, let's... 阅读全文
posted @ 2015-06-07 01:13 jianchao-li 阅读(408) 评论(0) 推荐(0) 编辑
摘要: Well, the problem does not aim for an advanced algorithm like KMP but only a clean brute-force algorithm. So we can traverse all the possible starting... 阅读全文
posted @ 2015-06-06 22:27 jianchao-li 阅读(297) 评论(0) 推荐(0) 编辑
摘要: In this problem, we are asked to divide two integers. However, we are not allowed to use division, multiplication and mod operations. So, what else ca... 阅读全文
posted @ 2015-06-06 22:01 jianchao-li 阅读(199) 评论(0) 推荐(0) 编辑
摘要: To readncharacters, we first callread4forn / 4times. For example, if we want to read10characters, we will read them in the8 (4 * 2) + 2manner by first... 阅读全文
posted @ 2015-06-05 16:25 jianchao-li 阅读(266) 评论(0) 推荐(0) 编辑
摘要: Problem Description:Design and implement a TwoSum class. It should support the following operations:addandfind.add- Add the number to an internal data... 阅读全文
posted @ 2015-06-05 13:24 jianchao-li 阅读(251) 评论(0) 推荐(0) 编辑
摘要: Recently I systematicall review some sorting algorithms, including insertion sort, bubble sort, merge sort and quick sort. I then implement them in C+... 阅读全文
posted @ 2015-06-04 22:45 jianchao-li 阅读(362) 评论(0) 推荐(0) 编辑
摘要: Recently I reviewed the classic heapsort algorithm and implement it according to contents in Introduction to Algorithms (3rd edition). The heap data s... 阅读全文
posted @ 2015-06-04 22:33 jianchao-li 阅读(256) 评论(0) 推荐(0) 编辑
摘要: The problem has a nice structure that backtracking naturally fits in. The structure is, given a starting positionidx, we search fromidxtill the end of... 阅读全文
posted @ 2015-06-04 20:35 jianchao-li 阅读(182) 评论(0) 推荐(0) 编辑
摘要: This problem is somewhat tricky at first glance. However, the final implementation is fairly simple using recursion.The basic idea is, visiting every ... 阅读全文
posted @ 2015-06-04 10:00 jianchao-li 阅读(257) 评论(0) 推荐(0) 编辑
摘要: Well, this problem desires for the use of dynamic programming. They key to any DP problem is to come up with the state equation. In this problem, we d... 阅读全文
posted @ 2015-06-03 11:54 jianchao-li 阅读(3676) 评论(0) 推荐(0) 编辑