add a O(n) solution, accepted