simple traversal?

  • 0

    Why not simply traverse the bst in-order and add everything to a list?
    Then for hasNext you get length of list(or keep length counter which is even faster)
    and for Next you simply pop the first element off the list O(1).

    The storage would be O(n) for initialize but next/hasnext don't use extra space.

Log in to reply

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