leetcode2sumc-three-sum:三和

时间:2021-07-06 17:44:02
【文件属性】:
文件名称:leetcode2sumc-three-sum:三和
文件大小:2KB
文件格式:ZIP
更新时间:2021-07-06 17:44:02
系统开源 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, -1, 2] ] 实现 1 : O(n^3) 超出时间限制 :anxious_face_with_sweat: public static List< List< Integer > > threeSum( int [] nums) { List< List< Integer > > result = new ArrayList< List< Integer > > (); if (nums == null || nums . length < 3 ) return result; int n = nums . length; for ( int i = 0 ; i < n - 2 ; i ++ ) { for
【文件预览】:
three-sum-master
----README.md(4KB)

网友评论