Resolve the problem from another aspect


  • 0
    O

    Since it's full tree, we can use the index (1 ~ 2^n-1) to find the next element. The binary form of the index can determine whether we go to left or right node. So for each element we can use O(logn), total O(nlogn) time complexity and O(1) space.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.