add a O(n) solution