Analysis:
Use custom TreeNode with
leftcnt
andcnt
attributes.leftcnt
depict the numbers smaller than the current node.cnt
represent the nodes has the same value before current node
Time Complexity:
- O(n)
Space Complexity:
- O(n)
Code
1 | class TreeNode(object): |