time O(n) , using hash