add O(1) space sol according to winnie, TODO O(n) time solution