O(n) by stack