1. 首页
  2. 考试认证
  3. 其它
  4. leetcode2sumc three sum 三和

leetcode2sumc three sum 三和

上传者: 2024-10-08 17:03:11上传 ZIP文件 1.67KB 热度 4次
leetcode 2和c三和给定一个由n个整数组成的数组nums,nums中是否有元素a、b、c使得a + b + c = 0?在数组中找到所有唯一的三元组,其总和为零。注意:解决方案集不得包含重复的三元组。 Example: Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is: [ [-1, 0, 1], [-1, 2] ]实现1 : O(n^3)超出时间限制:anxious_face_with_sweat: public static List< Integer > > threeSum( int [] nums) { List< Integer > > result = new ArrayList< Integer > > (); tif (nums == null || nums . length < 3 ) treturn result; t tint n = nums . length; tfor ( int i = 0 ; i < n - 2 ; i ++ ) { t for
下载地址
用户评论