Solution 1 Time complexity is O(n). Space complexity is O(n). Solution 2 Time complexity is O(n). Space complexity is O(1).

# Author Archives: bubufacai

## LeetCode 136 – Python 3 (Week 2 – 09)

Solution 1 Time complexity is O(n). Space complexity is O(1). Solution 2 Time complexity is O(n*n). Iterating through nums takes O(n) time * search num in the list takes O(n) time. Space complexity is O(n). n is the size of the list. Solution 3 Time complexity is O(n). Iterating through nums takes O(n) time * search num in the dictionary takes […]

## LeetCode 121 – Python 3 (Week 2 – 08)

Solution 1 Time complexity is 0(n). Space complexity is O(1).

## LeetCode 94 – Python 3 (Week 2 – 07)

Inorder traversal a tree: traverse the left subtree -> the root -> traverse the right subtree. Solution 1 Solution 2 Both time complexities are O(n). Both space complexities are O(n).

## LeetCode 175 – MySQL (Week 2 – 06)

select FirstName, LastName, City, Statefrom Person left join Addresson Person.PersonId = Address.PersonId;

## LeetCode 104 – Python 3 (Week 2 – 05)

Solution 1 class Solution: def maxDepth(self, root: TreeNode) -> int: if root is None: return 0 else: return max(self.maxDepth(root.left), self.maxDepth(root.right))+1 Time complexity is O(n). Space complexity is O(n).

## LeetCode 101 – Python 3 (Week 2 – 04)

A tree is symmetric if the left subtree is a mirror reflection of the right subtree. If the left subtree is a mirror reflection of the right subtree, two subtrees should have same root value. The left subtree of left subtree should also be a mirror reflection of the right subtree of right subtree. Solution […]

## LeetCode 70 – Python 3 (Week 2 – 03)

There are two ways to climb n steps: (1) climb n-1 steps + climb one step (2) climb n-2 steps + climb two step. The basic idea is that the ways for n steps is the sum of ways for n-1 steps and n-2 steps. If we use recurrence, the time complexity is high. Thus, […]

## LeetCode 53 – Python 3 (Week 2 – 02)

Solution 1 Time complexity is O(n). Space complexity is O(1).

## LeetCode 21 – Python 3 (Week 2 – 01)

Solution 1 (Runtime: 40 ms Memory Usage: 13.9 MB) Time complexity is O(m+n). Space complexity is O(1). Solution 2 (Runtime: 44 ms Memory Usage: 13.8 MB) Time complexity is O(m+n). Space complexity is O(m+n).