随笔分类 -  LeetCode Solutions

上一页 1 2 3 4 5 6 7 8 9 ··· 12 下一页
Solutions to problems on https://leetcode.com/problemset/algorithms/.
摘要: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 阅读(178) 评论(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 阅读(204) 评论(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 阅读(3015) 评论(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 阅读(201) 评论(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 阅读(158) 评论(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 阅读(214) 评论(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 阅读(169) 评论(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 阅读(153) 评论(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 阅读(305) 评论(0) 推荐(0)
摘要:This problem can be solved easily once you find the regularities :-) This link has done it for you. You may refer to its Python version. I rewrite it ... 阅读全文
posted @ 2015-08-08 14:52 jianchao-li 阅读(1439) 评论(0) 推荐(0)
摘要:Problem Description:Given an array of meeting time intervals consisting of start and end times[[s1,e1],[s2,e2],...](si& intervals) { 4 sort(in... 阅读全文
posted @ 2015-08-08 14:24 jianchao-li 阅读(4721) 评论(1) 推荐(0)
摘要:Problem Description: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person 阅读全文
posted @ 2015-08-08 13:44 jianchao-li 阅读(2281) 评论(0) 推荐(0)
摘要:Problem Description:A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Write a function to dete... 阅读全文
posted @ 2015-08-06 16:09 jianchao-li 阅读(2127) 评论(0) 推荐(0)
摘要:Problem Description:This is afollow upofShortest Word Distance. The only difference is now you are given the list of words and your method will be cal... 阅读全文
posted @ 2015-08-05 17:17 jianchao-li 阅读(3650) 评论(0) 推荐(0)
摘要:Problem Description:Given a list of words and two wordsword1andword2, return the shortest distance between these two words in the list.For example,Ass... 阅读全文
posted @ 2015-08-05 16:02 jianchao-li 阅读(3777) 评论(0) 推荐(0)
摘要:Problem Description: Implement an iterator to flatten a 2d vector.For example,Given 2d vector =[ [1,2], [3], [4,5,6]]By callingnextrepeatedly unti... 阅读全文
posted @ 2015-08-05 15:16 jianchao-li 阅读(2989) 评论(0) 推荐(0)
摘要:A relatively difficult tree problem. Well, a recursive solution still gives clean codes. The tricky part of this problem is how to record the result. ... 阅读全文
posted @ 2015-08-04 21:52 jianchao-li 阅读(238) 评论(0) 推荐(0)
摘要:An extension of Best Time to Buy and Sell Stock III. The idea is still to use dynamic programming (see here for detailed introduction). However, in th... 阅读全文
posted @ 2015-08-04 17:23 jianchao-li 阅读(228) 评论(0) 推荐(0)
摘要:Personally, this is a relatively difficult DP problem. This link posts a typical DP solution to it. You may need some time to get how it works.The cod... 阅读全文
posted @ 2015-08-03 14:49 jianchao-li 阅读(229) 评论(0) 推荐(0)
摘要:The function signature has been updated to return a more intuitivevector>which treats a single string as a group of anagrams consisting of only itself... 阅读全文
posted @ 2015-08-01 17:07 jianchao-li 阅读(876) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 8 9 ··· 12 下一页