leecode笔记 KSUM

来源:互联网 发布:深圳 户外 知乎 编辑:程序博客网 时间:2024/06/07 07:00

leecode题号:已完成 1Two Sum ,15 3Sum   

未完成  2,16,18

1. 

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

解法1 复杂度O(n^2) for嵌套


15. 3Sum

Given an array S of n integers, are there elements abc in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.

排序-->for循环(取队列中的一个数)-->逐一测左+右+target是否为0

原创粉丝点击