随笔分类 - LeetCode Solutions
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 ...
        阅读全文
                
摘要: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 ...
        阅读全文
                
摘要: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...
        阅读全文
                
摘要: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 ...
        阅读全文
                
摘要: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...
        阅读全文
                
摘要: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...
        阅读全文
                
摘要: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...
        阅读全文
                
摘要: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...
        阅读全文
                
摘要:This problem has a naive solution usingsortand linear scan. The suggested solution uses the idea ofbucket sort. The following is a C++ implementation ...
        阅读全文
                
摘要: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 ...
        阅读全文
                
摘要:Problem Description:Given an array of meeting time intervals consisting of start and end times[[s1,e1],[s2,e2],...](si& intervals) { 4 sort(in...
        阅读全文
                
摘要: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
        阅读全文
                
摘要: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...
        阅读全文
                
摘要: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...
        阅读全文
                
摘要:Problem Description:Given a list of words and two wordsword1andword2, return the shortest distance between these two words in the list.For example,Ass...
        阅读全文
                
摘要:Problem Description: Implement an iterator to flatten a 2d vector.For example,Given 2d vector =[ [1,2], [3], [4,5,6]]By callingnextrepeatedly unti...
        阅读全文
                
摘要: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. ...
        阅读全文
                
摘要: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...
        阅读全文
                
摘要: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...
        阅读全文
                
摘要: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...
        阅读全文
                
                    
                
浙公网安备 33010602011771号