当前位置:网站首页>LeetCoed18. Sum of four numbers
LeetCoed18. Sum of four numbers
2022-04-23 08:09:00 【Want to get into Ali's chicken】
Ideas
The same idea as the sum of three , It also uses a double pointer, which is to add an extra layer on the outside for Circulation is enough .
Code
class Solution {
public List<List<Integer>> fourSum(int[] nums, int target) {
Arrays.sort(nums);
int temp = 0;
int left = 0;
int j = 0;
int right = 0;
List<List<Integer>> res = new ArrayList<>();
Set<List<Integer>> set = new HashSet<>();
for(int i =0;i<nums.length-2;i++){
for(j = i+1;j<nums.length-2;j++){
left = j+1;
right = nums.length-1;
while(right>left){
temp = nums[i] + nums[j]+nums[left]+nums[right];
if(temp > target){
right--;
}else if(temp < target){
left++;
}else{
set.add(Arrays.asList(nums[i],nums[j],nums[left],nums[right]));
left++;
right--;
}
}
}
}
for(List<Integer> a:set){
res.add(a);
}
return res;
}
}
版权声明
本文为[Want to get into Ali's chicken]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230641067646.html
边栏推荐
- PHP generates short links: convert numbers to letters and letters to numbers
- 【Appium】测试时遇到手机内嵌H5页面的切换问题
- [programming practice / embedded competition] learning record of embedded competition (II): picture streaming based on TCP
- CSV Column Extract列提取
- KCD_ EXCEL_ OLE_ TO_ INT_ Convert reports an error sy subrc = 2
- [problem solving] vs2019 solves the problem that the EXE file generated by compilation cannot be opened
- [Effective Go 中文翻译] 第一篇
- 一个没啥L用,但可以装X的IDEA插件
- Fibula dynamic programming
- 云计算技能大赛 -- openstack私有云环境 第二部分
猜你喜欢
How to import Excel data in SQL server, 2019 Edition
Ctf-misc learning from start to give up
BUUCTF [极客大挑战 2019]EasySQL1
1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
Anti shake and throttling
SAP self created table log function is enabled
BUFFCTF文件中的秘密1
在线YAML转XML工具
Intranet penetration series: ICMP of Intranet tunnel_ Tran
Go语学习笔记 - 语言接口 | 从零开始Go语言
随机推荐
A series of articles, a summary of common vulnerabilities of Web penetration (continuously updated)
Analysis of Nacos source code
Ribbon启动流程
Hump naming object
Go语学习笔记 - 语言接口 | 从零开始Go语言
Essays (updated from time to time)
1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
feign如何集成hystrix
SAP sto with billing process and configuration
LeetCode 1611. 使整数变为 0 的最少操作次数
The displayed amount of ABAP ALV is inconsistent with the exported amount
智能名片小程序名片详情页功能实现关键代码
MYSQL——第一章节(数据类型2)
访问数据库的时候出现错误 Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY.详解
Planification du mouvement du manipulateur dans l'assemblage 3c
Draw a circle quickly in MATLAB (the one that can be drawn directly given the coordinates and radius of the center of the circle)
Ignis公链的NFT生态发展:Unicorn.art的捐赠开发之路
利用sqlmap注入获取网址管理员账号密码
渗透测试面试合集---HVV---
Learning records of some shooting ranges: sqli labs, upload labs, XSS