10 2019 档案
Leetcode: Closest Leaf in a Binary Tree
摘要:Tree > Graph Note only the nodes visited in DFS are put into the backedgeMap, the others don't. This is fine, cause only from KNode to root this path,
阅读全文
Amazon | OA 2019 | Optimal Utilization
摘要:2-Pointers Syntax side: Pay attention to how to print an array: System.out.println(Arrays.toString(int[] item));
阅读全文
Leetcode: Split BST
摘要:Note: The size of the BST will not exceed 50. The BST is always valid and each node's value is different. Note: The size of the BST will not exceed 50
阅读全文
Leetcode: Optimize Water Distribution in a Village && Summary: Union Find and Minimum Spanning Tree
只有注册用户登录后才能阅读该文。
Leetcode: Rotated Digits
摘要:X is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from X. Each digit must be rotated - we cannot choose to leave it alone. A number i
阅读全文
Leetcode: Repeated String Match
摘要:The idea is to keep string builder and appending until the length A is greater or equal to B. use a while loop to keep adding A to stringBuilder until
阅读全文
Leetcode: Student Attendance Record I
摘要:1-liner s.contains("") normally is O(nm), but can be optimized to be O(n) O(n) scan
阅读全文
Leetcode: Robot Room Cleaner
摘要:Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. The robot cleaner with 4 given APIs can move forward, turn left or turn right. Each turn it made is...
阅读全文
Leetcode: Most Stones Removed with Same Row or Column
摘要:If stone a and stone b are in the same column/row, we connect them as a component The largest possible number of moves we can make = the number of uni
阅读全文
Leetcode: 24 Game
摘要:Backtracking: every time draw two cards, calculate the possible results, and add one result to the nextRound list. The nextRound list will have the re
阅读全文
Leetcode: Capacity To Ship Packages Within D Days
摘要:Exactly the same with Split Array Largest Sum. Binary search or DP Binary Search
阅读全文
Leetcode: Stream of Characters
摘要:Store the words in the trie with reverse order, and check the query string from the end
阅读全文
Leetcode: Backspace String Compare
摘要:Complexity Analysis Time Complexity: O(M + N)O(M+N), where M, NM,N are the lengths of S and T respectively. Space Complexity: O(1)O(1). Time Complexit
阅读全文
Leetcode: Shortest Way to Form String
摘要:Greedy Use two pointers, one for source: i, one for target: j. While j scan through target, try to match each char of j in source by moving i. Count h
阅读全文
Leetcode: Campus Bikes II
摘要:Basic: Backtracking + pruning DP: refer to https://leetcode.com/problems/campus-bikes-ii/discuss/305218/DFS-%2B-Pruning-And-DP-Solution state : dp[i][
阅读全文
Leetcode: Minimum Domino Rotations For Equal Row
摘要:1. The final uniform character should be either A[0] or B[0] 2. A[0] could be at the top, or the bottom. Same applies to B[0] 3. If A[0] works, no nee
阅读全文