上一页 1 2 3 4 5 6 7 8 9 10 ··· 20 下一页
摘要: 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 阅读(181) 评论(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 阅读(157) 评论(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 阅读(152) 评论(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 阅读(168) 评论(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 阅读(171) 评论(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 阅读(207) 评论(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) 编辑
摘要: Problem Description:There are a row ofnhouses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each h... 阅读全文
posted @ 2015-08-14 14:44 jianchao-li 阅读(3007) 评论(0) 推荐(0) 编辑
摘要: This problem can be solved by DP elegantly. You may refer to this link for the code and explanations.I try to rewrite the code, also in C++, but find ... 阅读全文
posted @ 2015-08-11 22:08 jianchao-li 阅读(192) 评论(0) 推荐(0) 编辑
摘要: The idea is just to perform the addition from right to left as usual :-)Note that the result may be longer than the originaldigitsby1number (the carry... 阅读全文
posted @ 2015-08-11 09:43 jianchao-li 阅读(152) 评论(0) 推荐(0) 编辑
摘要: The idea is just to add the elements in the spiral order. First the up-most row (u), then the right-most column (r), then the down-most row (d), and f... 阅读全文
posted @ 2015-08-11 08:51 jianchao-li 阅读(204) 评论(0) 推荐(0) 编辑
摘要: The idea is just to generate the matrix in the spiral order. First the up-most row (u), then the right-most column (r), then the down-most row (d), an... 阅读全文
posted @ 2015-08-11 08:42 jianchao-li 阅读(162) 评论(0) 推荐(0) 编辑
摘要: A simple and in-place idea: first reverse the image in row-major order and then transpose it :-) 1 class Solution { 2 public: 3 void rotate(vector... 阅读全文
posted @ 2015-08-10 13:45 jianchao-li 阅读(145) 评论(0) 推荐(0) 编辑
摘要: This problem has a naive solution usingsortand linear scan. The suggested solution uses the idea ofbucket sort. The following is a C++ implementation ... 阅读全文
posted @ 2015-08-10 11:03 jianchao-li 阅读(277) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 20 下一页