当前位置:网站首页>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
边栏推荐
- GUI,CLI与Unix哲学
- 国基北盛-openstack-容器云-环境搭建
- Dvwa 靶场练习记录
- 云计算技能大赛 -- openstack私有云环境 第二部分
- Alibaba sentinel学习QA
- Quick rehearsal exercise
- MySQL——第一章节(MySQL中的数据类型)
- [Effective Go 中文翻译]函数篇
- [programming practice / embedded competition] learning record of embedded competition (I): establishment of TCP server and web interface
- Chapter IV intangible assets
猜你喜欢

几种智能机器人室内定位方法对比

1216_MISRA_C规范学习笔记_控制流的规则要求

How to import Excel data in SQL server, 2019 Edition

Go语学习笔记 - 结构体 | 从零开始Go语言

Chapter IV intangible assets

SAP tr manual import system operation manual

MySQL--锁的奥秘--数据怎么锁

国基北盛-openstack-容器云-环境搭建

Go语学习笔记 - 语言接口 | 从零开始Go语言

Sto with billing cross company inventory dump return
随机推荐
MySQL -- the secret of lock -- how to lock data
BUUCTF [ACTF2020 新生赛]Include1
MYSQL——第一章节(数据类型2)
Anti shake and throttling
Hierarchical output binary tree
Research on system and software security (I)
C语言学习记录——삼십팔 字符串函数使用和剖析(2)
Talking about distributed storage from ES, mongodb, redis and rocketmq
输入 “ net start mysql ”,出现 “ 发生系统错误 5。 拒绝访问 ” 。问题详解
Upload labs range practice
Cloud computing skills competition -- Part 2 of openstack private cloud environment
Research on system and software security (5)
[untitled]
分布式服务治理Nacos
在线YAML转XML工具
1+x云计算中级--脚本搭建读写分离
Research on system and software security (2)
Chapter IV intangible assets
Implementation of promise all
Mobile terminal layout (3D conversion, animation)