随笔分类 - Leetcode
            
    Leetcode: Island Perimeter
    
            
            
        
摘要:You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely...
        阅读全文
            
        
            
    Leetcode: Can I Win
    
            
            
        
摘要:refer to https://discuss.leetcode.com/topic/68896/java-solution-using-hashmap-with-detailed-explanation After solving several "Game Playing" questions
        阅读全文
            
        
            
    Leetcode: Repeated Substring Pattern
    
            
            
        
摘要:这道题应该没法用DP等解,只能brute force 或者 KMP(为深究) BruteForce, Best Solution for now except KMP 作为Encode String with Shortest Length的subproblem KMP解法未研究,https://d
        阅读全文
            
        
            
    Leetcode: Assign Cookies
    
            
            
        
摘要:Solution 1: Greedy, Time:O(nlogn) Just assign the cookies starting from the child with less greediness to maximize the number of happy children . Solu
        阅读全文
            
        
            
    Leetcode: 132 Pattern
    
            
            
        
摘要:我觉得这道题是hard,难点第一是要想到用stack,第二是要维护一个这样子的min-max序列:So at any time in the stack, non-overlapping Pairs are formed in descending order by their min value,
        阅读全文
            
        
            
    Leetcode: Arithmetic Slices II - Subsequence
    
            
            
        
摘要:参考了https://discuss.leetcode.com/topic/67413/detailed-explanation-for-java-o-n-2-solution 这道题DP思路还是能想出来,Time O(N^2), Space O(N^2) T(i, d), which denote
        阅读全文
            
        
            
    Leetcode: Minimum Moves to Equal Array Elements II
    
            
            
        
摘要:Just like meeting point problem, find the median elements in the array after sorting, so Solution 1: Sort, find the median: O(NlogN) Solution 2: Quick
        阅读全文
            
        
            
    Leetcode: 4Sum II
    
            
            
        
摘要:一开始想了一个O(n^3), space O(N)的做法,后来发现还可以优化 Solution: time O(N^2), space O(N^2)
        阅读全文
            
        
            
    Leetcode: K-th Smallest in Lexicographical Order
    
            
            
        
摘要:第二遍做法:参考https://discuss.leetcode.com/topic/64624/concise-easy-to-understand-java-5ms-solution-with-explaination Actually this is a denary tree (each n
        阅读全文
            
        
            
    Leetcode: Minimum Number of Arrows to Burst Balloons
    
            
            
        
摘要:我的Greedy+Heap做法: Array按start moment升序sort,Heap里按end moment升序sort,一旦到Heap里结束时间最早的气球的end,就要扔arrow,这时在heap里的气球都会被引爆 改进:因为一旦气球爆了的话,Heap里面的元素要全部清空,不需要知道Hea
        阅读全文
            
        
            
    Leetcode: Minimum Moves to Equal Array Elements
    
            
            
        
摘要:idea 1: suppose it takes y steps to equal each elements, then this equation stands: (min + y) * num.length == sum + (num.length-1)*y, where min + y is
        阅读全文
            
        
            
    Leetcode: Number of Boomerangs
    
            
            
        
摘要:Solution: Use HashTable, Time: O(N^2), Space: O(N) 我的:注意14行是有value个重复distance,表示有value个点,他们跟指定点距离都是distance,需要选取2个做permutation, 所以是value * (value-1) 别
        阅读全文
            
        
            
    Leetcode: Arranging Coins
    
            
            
        
摘要:count is the # of level, sum is the accumulated coins Better Solution: Binary Search, 因为怕溢出,所以(1+m)m/2表示成了line6那种样子. 用m去估计最后返回的row
        阅读全文
            
        
            
    Leetcode: Path Sum III
    
            
            
        
摘要:Add the prefix sum to the hashMap, and check along path if hashMap.contains(pathSum+cur.val-target); My Solution 一个更简洁的solution: using HashMap to stor
        阅读全文
            
        
            
    Leetcode: All O`one Data Structure
    
            
            
        
摘要:Solution: O(1) time complexity 解题思路主要参考了网友ivancjw的帖子,数据结构参考了https://discuss.leetcode.com/topic/65634/java-ac-all-strict-o-1-not-average-o-1-easy-to-re
        阅读全文
            
        
            
    Leetcode: Find Right Interval
    
            
            
        
摘要:Solution 1: TreeMap, Time complexity: O(NlogN) 像这种在一个集合里面寻找有没有比某个数小的数,一般要么treeMap要么treeSet。Interval的题经常需要用treeMap, Data Stream as Disjoint Intervals 就
        阅读全文
            
        
            
    Leetcode: Non-overlapping Intervals
    
            
            
        
摘要:Actually, the problem is the same as "Given a collection of intervals, find the maximum number of intervals that are non-overlapping." (the classic Gr
        阅读全文
            
        
            
    Leetcode: Number of Segments in a String
    
            
            
        
摘要:用split() 不用API, better solution, O(N) time O(1) space
        阅读全文
            
        
            
    Leetcode: Strong Password Checker
    
            
            
        
摘要:refer to https://discuss.leetcode.com/topic/63854/o-n-java-solution-by-analyzing-changes-allowed-to-fix-each-problem http://www.cnblogs.com/grandyang/
        阅读全文
            
        
            
    G 面经 && Leetcode: Longest Repeating Character Replacement
    
            
    
摘要:真是被这道题气死了,总是弄不对 The problem says that we can make at most k changes to the string (any character can be replaced with any other character). So, let's 
        阅读全文
            
        
 
                    
                     
                    
                 
                    
                 
 浙公网安备 33010602011771号
浙公网安备 33010602011771号