随笔分类 - Leetcode
            
    Leetcode: Longest Substring with At Least K Repeating Characters
    
            
            
        
摘要:Analysis: Given a string s, find out all chars that are invalid (i.e., count < k). The longest substring must reside in one of the substrings divided 
        阅读全文
            
        
            
    Leetcode: Rotate Function
    
            
            
        
摘要:F(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25 [4, 3, 2, 6] F(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16 [6, 
        阅读全文
            
        
            
    Leetcode: UTF-8 Validation
    
            
            
        
摘要:这道题题干给出了判断 one single UTF-8 char的方法,然后给一个UTF-8 char sequence,判断是不是正确sequence. (读题读了很久) 这道题关键是要学到用 & 取出一个bit sequence当中几位的方法 二进制数表示法:在前面加 0b, 八进制加0o, 十
        阅读全文
            
        
            
    Leetcode: Decode String
    
            
            
        
摘要:自己的做法:这种括号问题肯定是用栈,最好是先在栈里存一个空元素,然后stack.peek().append()各种操作 一个栈存string, 一个栈存number, 维护一个指针numStart指向数字的开始 1. 遇到数字啥也不做 2. 遇到char: stack.peek().append(c
        阅读全文
            
        
            
    Leetcode: Perfect Rectangle
    
            
            
        
摘要:Refer to https://discuss.leetcode.com/topic/56052/really-easy-understanding-solution-o-n-java and https://discuss.leetcode.com/topic/55923/o-n-solutio
        阅读全文
            
        
            
    Leetcode: Random Pick Index
    
            
            
        
摘要:Three types of answer: Map Solution, O(N) memory, O(N) init, O(1) pick. Like @dettier's Reservoir Sampling. O(1) init, O(1) memory, but O(N) to pick. 
        阅读全文
            
        
            
    Leetcode: Sum of Left Leaves
    
            
            
        
摘要:Recursion: 是不是left子数完全由bottom往上第二层决定,如果是left子树且是叶子节点,那么就是left leaves, parent得告诉child是不是在left子树 BFS:
        阅读全文
            
        
            
    Leetcode: Is Subsequence
    
            
            
        
摘要:Basic Solution: DP, O(mn) time, O(m) space, m is the size of s, n is the size of t Greedy Solution: O(n) time, O(1) space Follow Up: The best solution
        阅读全文
            
        
            
    Leetcode: Elimination Game
    
            
            
        
            
        
摘要:refer to https://discuss.leetcode.com/topic/59293/java-easiest-solution-o-logn-with-explanation Time Complexity: O(log n) update and record head in ea
        阅读全文
            
        
            
    Leetcode: Longest Absolute File Path
    
            
            
        
摘要:Time Complexity: O(N) The depth of the directory/file is calculated by counting how many "\t"s are there.The time complexity is O(n) because each subs
        阅读全文
            
        
            
    Leetcode: Mini Parser
    
            
            
        
摘要:有括号这种一般要用stack, stack top 就是当前着眼的那一个NestedInteger, 可以对其添加新的元素。 注意47行判断很关键,顺带处理了 "[]," 括号后面是逗号的情况
        阅读全文
            
        
            
    Leetcode: First Unique Character in a String
    
            
            
        
摘要:Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note: You may a...
        阅读全文
            
        
            
    Leetcode: Lexicographical Numbers
    
            
            
        
            
        
            
        
摘要:Solution 1: Solution 2: O(N) time, O(1) space The basic idea is to find the next number to add.Take 45 for example: if the current number is 45, the n
        阅读全文
            
        
            
    Leetcode: Linked List Random Node
    
            
            
        
摘要:Solution 1: Reservior sampling: (wiki introduction) Reservoir sampling is a family of randomized algorithms for randomly choosing a sample of k items 
        阅读全文
            
        
            
    Leetcode: Insert Delete GetRandom O(1) - Duplicates allowed
    
            
            
        
摘要:The idea is to add a set to the hashMap to remember all the locations of a duplicated number.
        阅读全文
            
        
            
    Leetcode: Insert Delete GetRandom O(1)
    
            
            
        
摘要:最先想到是用double LinkedList+Map, 没必要,arraylist+map就够了;另外取random的方法还有,rand.nextInt(int n) returns an integer in the range [0, n) java.util.Random rand = ne
        阅读全文
            
        
            
    Leetcode: Kth Smallest Element in a Sorted Matrix
    
            
    
摘要:Heap: you need to know the row number and column number of that element(so we can create a tuple class here) Binary Search方法:(12/28仔细看了之后觉得没必要深究,有时间再去
        阅读全文
            
        
 
                    
                 
 浙公网安备 33010602011771号
浙公网安备 33010602011771号