Month: December 2018
951 Flip Equivalent Binary Trees
Link: https://leetcode.com/problems/flip-equivalent-binary-trees/ Thought If 2 nodes are equivalent, either their left and right side match, or they are flipped match. So using a recursion(why recursion? It is a Tree!), and try to match each node pairs from root1 and root2. For each recursion level, I will first compare if current node pair have the same value. […]
Read More → 951 Flip Equivalent Binary Trees950 Reveal Cards In Increasing Order
link: https://leetcode.com/problems/reveal-cards-in-increasing-order/ Thought So the rule is if you pop anything from front, then you shall move next head to tail. Reversely, if we want to build the original sequence, we could assume if you want to insert anything in head, you should pop your tail, and push the tail to head Code Runtime Time: O(n)Space: […]
Read More → 950 Reveal Cards In Increasing Order949 Largest Time for Given Digits
link: https://leetcode.com/problems/largest-time-for-given-digits/ Thought Its easy to think use DFS to solve it: it has limit data(4 digits), and DFS will enumerates all possible combinations Code Runtime Time: O(n!)Space: O(n!)
Read More → 949 Largest Time for Given Digits