v1 time O(n) space O(1) Accepted

test with brain is key to bug-free code!