随笔分类 - Leetcode
            
    Leetcode: Integer Break
    
            
            
        
摘要:O(N^2)解法: DP dp[i] represent the maximum product of breaking up integer i O(N)解法: the best factor is 3. we keep breaking n into 3's until n gets small
        阅读全文
            
        
            
    Leetcode: Flatten Nested List Iterator
    
            
            
        
摘要:非常精巧地使用stack。push all the nestedList into the stack from back to front,so when we pop the stack, it returns the very first element 执行hasNext()的时候,如果pe
        阅读全文
            
        
            
    Leetcode: Reverse String
    
            
            
        
摘要:After the API changes 注意没有append(0, s.charAt(i)), 是sb.insert(0, charAt(i));
        阅读全文
            
        
            
    Leetcode: Power of Four
    
            
            
        
摘要:it's easy to find that power of 4 numbers have those 3 common features. First,greater than 0. Second,only have one '1' bit in their binary notation,so
        阅读全文
            
        
            
    Leetcode: House Robber III
    
            
            
        
            
        
摘要:https://discuss.leetcode.com/topic/39834/step-by-step-tackling-of-the-problem rob(root) which will return the maximum amount of money that we can rob 
        阅读全文
            
        
            
    Leetcode: Palindrome Pairs
    
            
            
        
摘要:Naive Solution: Time: O(n^2*k) with n the total number of words in the "words" array and k the average length of each word: check each combination see
        阅读全文
            
        
            
    Leetcode: Self Crossing
    
            
            
        
摘要:4th line may cross with 1st line, and so on: 5th with 2nd, ...etc 5th line may cross with 1st line, and so on: 6th with 2nd, ...etc 6th line also may 
        阅读全文
            
        
            
    Leetcode: Increasing Triplet Subsequence
    
            
            
        
摘要:Naive Solution: use DP, Time O(N^2), Space O(N) dp[i] represents the length of longest increasing subsequence till i including element i in nums array
        阅读全文
            
        
            
    Leetcode: Reconstruct Itinerary
    
            
            
        
摘要:refer to Recursion https://leetcode.com/discuss/84702/share-my-solution and Iteration https://leetcode.com/discuss/84706/share-solution-java-greedy-st
        阅读全文
            
        
            
    Leetcode: Verify Preorder Serialization of a Binary Tree
    
            
            
        
摘要:One way to serialize a binary tree is to use pre-oder traversal. When we encounter a non-null node, we record the node's value. If it is a null node, 
        阅读全文
            
        
            
    Leetcode: Patching Array
    
            
            
        
摘要:Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be for
        阅读全文
            
        
            
    Leetcode: Longest Increasing Path in a Matrix
    
            
            
        
摘要:DFS + DP: use a two dimensional matrix dp[i][j] to store the length of the longest increasing path starting at matrix[i][j] transferring function is: 
        阅读全文
            
        
            
    Leetcode: Range Sum Query 2D - Mutable  && Summary: Binary Indexed Tree
    
            
            
        
摘要:参考:https://leetcode.com/discuss/72685/share-my-java-2-d-binary-indexed-tree-solution Build binary indexed tree takes : O(mn*logm*logn) time, both upda
        阅读全文
            
        
            
    Leetcode: Odd Even Linked List
    
            
            
        
摘要:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the...
        阅读全文
            
        
            
    Leetcode: Count of Range Sum
    
            
            
        
摘要:Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive. Range sum S(i, j) is defined as the sum of the elem
        阅读全文
            
        
            
    Leetcode: Power of Three
    
            
            
        
摘要:Given an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion? Recursion: 1
        阅读全文
            
        
            
    Leetcode: Maximum Size Subarray Sum Equals k
    
            
            
        
摘要:Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.Example 1:Given n...
        阅读全文
            
        
            
    Leetcode: Range Sum Query - Mutable && Summary: Segment Tree
    
            
            
        
摘要:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by upda...
        阅读全文
            
        
            
    Leetcode: Create Maximum Number
    
            
    
摘要:Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k 0 && n-i-1>=count-j && res[j-1]arr2...
        阅读全文
            
        
 
                    
                     
                    
                 
                    
                 
 浙公网安备 33010602011771号
浙公网安备 33010602011771号