Leetcode 16
2024-09-20 12:21:41
//一次AC 有点爽的
class Solution {
public:
int threeSumClosest(vector<int>& nums, int target) {
int res = ;
int minal = INT_MAX;
sort(nums.begin(),nums.end());
for(int i=;i < nums.size()-;i++){
int cnt = target-nums[i];
for(int j=i+,k=nums.size()-;j < k;){
int sum = nums[j]+nums[k];
if(sum < cnt){j++;}
else if(sum > cnt){k--;}
else{
res = target;
return res;
}
if(minal > abs(sum-cnt)){minal = abs(sum-cnt);res = sum+nums[i];}
}
}
return res;
}
};
最新文章
- UniqueIdentifier 数据类型 和 GUID 生成函数
- 嵌入式Linux学习入门:控制LED灯
- 卡拉兹(Callatz)猜想
- ping提示小结
- 快速诊断Linux性能
- <;Win32_1>;深入浅出windows消息机制[转自crocodile_]
- NOIP201501&;&;02
- A题笔记(5)
- ssh公钥认证原理及设置root外的其他用户登录ssh
- What Kind of Friends Are You? ZOJ 3960
- 【转载】C++ vector的用法
- vxworks开发中simulator的使用之建立虚拟网卡
- Git要点
- python之requests 乱七八糟
- 009-ThreadPoolExecutor运转机制详解,线程池使用1-newFixedThreadPool、newCachedThreadPool、newSingleThreadExecutor、newScheduledThreadPool
- tablib.Dataset()操作exl类型数据之“类方法”研究
- React - 环境准备
- vue使用sweetalert2弹窗插件
- Selenium IDE的一些操作
- code#5 P1 报告
热门文章
- C++ string append方法的常用用法
- 设计模式之&mdash;&mdash;Memento模式
- 【查看】mysql 常规书写注意事项(那些坑)
- wget 命令大全
- SaltStack系列(三)之state相关介绍
- [py][lc]python高阶函数(匿名/map/reduce/sorted)
- testng日志和报告
- Which adidas NMD Singapore is your favorite
- Java之Integer源码
- 470. Implement Rand10() Using Rand7() (拒绝采样Reject Sampling)