Time O(n^m). Space O(n^m). n is length of dict. m is length of longest word.
Category Archives: Uncategorized
Find Leaves of Binary Tree – Python 3 (Week 12 – 18)
Time O(n). Space O(n).
Word Break II – Python 3 (Week 12 – 17)
Time O(mn). Space O(mn).
Binary Tree Upside Down – Python 3 (Week 12 – 16)
Time O(h). Space O(h).
Inorder Successor in BST – Python 3 (Week 12 – 15)
class Solution: “”” @param: root: The root of the BST. @param: p: You need find the successor node of p. @return: Successor of p. “”” def inorderSuccessor(self, root, p): # write your code here if root == None or p == None: return None if root.val <= p.val: return self.inorderSuccessor(root.right, p) else: leftAns = self.inorderSuccessor(root.left, …
Continue reading “Inorder Successor in BST – Python 3 (Week 12 – 15)”
Sliding Puzzle II – Python 3 (Week 12 – 14)
Solution I BFS Time O(1). Space O(1).
Open the Lock – Python 3 (Week 12 – 13)
Time O(n). Space O(n).
Zombie in Matrix – Python 3 (Week 12 – 12)
Time O(nm). Space O(mn).
Walls and Gates – Python 3 (Week 12 – 11)
Time O(nm). Space O(nm).
Surrounded Regions – Python 3 (Week 12 – 10)
Solution 1 BFS Time O(n * m). Space O(n * m). Solution 2 BFS