v1 time O(n) space O(n^2) Accepted