
Solution:
Sort then using two pointers, one at the beginning element, one at the end element, moving towards, calculate the sum of three elements.
time: O(N^2) , space: O(1)

总结:
考虑non-descending,先sort数组,其次考虑去除duplicate; 类似2sum,可以利用two pointers,不断移动left 和 right 指针,直到找到目标,或者两指针相遇
update:
用hashSet 去重, 增加 O(N) 空间

网友评论