摘要: This problem is just similar toMinimum Depth of Binary Tree.The first solution also uses recursion (not sure whether it can be called DFS).1 class Sol... 阅读全文
posted @ 2015-08-15 18:43 jianchao-li 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Well, this problem has the highest acceptance rate among all OJ problems. It has a very easy 1-line reursive solution. I am not sure whether this one ... 阅读全文
posted @ 2015-08-15 18:23 jianchao-li 阅读(172) 评论(0) 推荐(0) 编辑
摘要: The basic idea is to use binary search: keep two pointerslandrfor the current search range, then find the middle elementnums[mid]in this range. Ifnums... 阅读全文
posted @ 2015-08-15 17:41 jianchao-li 阅读(172) 评论(0) 推荐(0) 编辑
摘要: The idea is to search for the left and right boundaries of target via two binary searches. Well, some tricks may be needed. Take a look at this link :... 阅读全文
posted @ 2015-08-15 16:23 jianchao-li 阅读(180) 评论(0) 推荐(0) 编辑
摘要: The most obvious idea is to maintain two divisors to get the most and least significantdigits and compare them. Well, there are much more clever ideas... 阅读全文
posted @ 2015-08-15 15:32 jianchao-li 阅读(156) 评论(0) 推荐(0) 编辑
摘要: The idea is to add the two numbers (represented by linked lists) nodes after nodes and store the result in the longer list. Since we may append the ad... 阅读全文
posted @ 2015-08-15 14:59 jianchao-li 阅读(150) 评论(0) 推荐(0) 编辑
摘要: The basic idea is to maintain a hash table for each elementnuminnums, usingnumas key and its index (1-based) as value. For eachnum, search fortarget -... 阅读全文
posted @ 2015-08-15 11:51 jianchao-li 阅读(167) 评论(0) 推荐(0) 编辑
摘要: This problem can be solved easily if we are allowed to use more than O(1) space. For example, you may create a copy of the original matrix (O(mn)-spac... 阅读全文
posted @ 2015-08-15 11:33 jianchao-li 阅读(169) 评论(0) 推荐(0) 编辑
摘要: This problem is a little tricky at first glance. However, if you have finished theHouse Robberproblem, this problem can simply bedecomposed into two H... 阅读全文
posted @ 2015-08-15 11:23 jianchao-li 阅读(206) 评论(0) 推荐(0) 编辑
摘要: Since we are not allowed to rob two adjacent houses, we keep two variablespreandcur. During thei-th loop,prerecords the maximum profit that we do not ... 阅读全文
posted @ 2015-08-15 11:12 jianchao-li 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Well, this problem can be solved in 1-line clearly. Take a look at this link:-)1 class Solution {2 public:3 string convertToTitle(int n) {4 ... 阅读全文
posted @ 2015-08-15 00:41 jianchao-li 阅读(195) 评论(0) 推荐(0) 编辑