v2 time O(n) space O(height) Accepted

fix typo in v1