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 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, …

Design a site like this with WordPress.com
Get started