111. Minimum Depth of Binary Tree

BFS solution ```python Definition for a binary tree node. class TreeNode: def init(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def minDepth(self, root: TreeNode) -> int: if not root: return 0 q = collections.deque([(root,1)]) while q: node, level = q.popleft() if not node.left... [Read More]
Tags: Tree DFS BFS

739. Daily Temperatures

```python “”” main idea is (monotonous stack) to loop through each element in the T, record with old temprature with stack(from old to most recent). compare current temperate with most recent temperature, if current is higher than most recent, get the difference with current and most recent, store into result... [Read More]

364. Nested List Weight Sum II

time O(N) space O(H) Two pass ```python ””” This is the interface that allows for creating nested lists. You should not implement it, or speculate about its implementation ””” #class NestedInteger: def init(self, value=None): ””” If value is not specified, initializes an empty list. Otherwise initializes a single integer equal... [Read More]
Tags: DFS