Time:O(n), Space:O(1)