## 3Sum 超时 原

依姆哣特

``````class Solution {
public:
vector<vector<int>> threeSum(vector<int>& nums) {
int len = int(nums.size());

sort(nums.begin(), nums.end(),less<int>());

int newlenth = len*(len-1)*(len-2)/6;
vector<vector<int>> res(newlenth,vector<int>(3,0));
//vector<vector <int> > ivec(m ,vector<int>(n,0));
int p=0;
for (int i=0; i<len; i++) {
if(i > 0 && nums[i] == nums[i-1]){
continue;
}
for (int j=i+1; j<len; j++) {
if(j > 0 && nums[j] == nums[j-1]){
continue;
}
for (int k=j+1; k<len; k++) {
if(k > 0 && nums[k] == nums[k-1]){
continue;
}
if (nums[i]+nums[j]+nums[k]==0) {
cout<<i<<endl<<j<<endl<<k<<endl;
res[p][0]=nums[i];
res[p][1]=nums[j];
res[p][2]=nums[k];
cout<<res[p][0]<<" "<<res[p][1]<< " "<<res[p][2]<<endl;
p++;
}
}
}
}
return res;
}
};``````

### 依姆哣特

923. 3Sum With Multiplicity - LeetCode

Question 923. 3Sum With Multiplicity Solution 题目大意： 给一个int数组A和一个目标值target,求满足下面两个条件的组合个数,其中i,j,k分别为数组的索引 i target = A[i] + A[j] + A[k] 思...

yysue
2018/10/22
0
0
Leetcode_Problem 16_3 Sum Closest

quiet_girl
2018/03/09
0
0
Lintcode59 3Sum Closest solution 题解

【题目描述】 Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. Notice:You ma......

Winnielyn
2018/06/26
0
0
Lintcode58 4Sum solution 题解

【题目描述】 Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target?Find all unique quadruplets in the array which gives the sum......

Winnielyn
2018/06/26
0
0

2016/12/12
3
0

import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServlet;import javax.serv......

gwl_

1
0

stars永恒

1
0

NotFound403

3
0
day22:

1、写一个getinterface.sh 脚本可以接受选项[i，I]，完成下面任务： 1）使用格式：getinterface.sh [-i interface | -I ip] 2）当用户使用-i选项时，显示指定网卡的IP地址；当用户使用-I选项...

2
0
Spring Cloud Alibaba基础教程：使用Nacos实现服务注册与发现

4
0