//一次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;
}
};

最新文章

  1. UniqueIdentifier 数据类型 和 GUID 生成函数
  2. 嵌入式Linux学习入门:控制LED灯
  3. 卡拉兹(Callatz)猜想
  4. ping提示小结
  5. 快速诊断Linux性能
  6. &lt;Win32_1&gt;深入浅出windows消息机制[转自crocodile_]
  7. NOIP201501&amp;&amp;02
  8. A题笔记(5)
  9. ssh公钥认证原理及设置root外的其他用户登录ssh
  10. What Kind of Friends Are You? ZOJ 3960
  11. 【转载】C++ vector的用法
  12. vxworks开发中simulator的使用之建立虚拟网卡
  13. Git要点
  14. python之requests 乱七八糟
  15. 009-ThreadPoolExecutor运转机制详解,线程池使用1-newFixedThreadPool、newCachedThreadPool、newSingleThreadExecutor、newScheduledThreadPool
  16. tablib.Dataset()操作exl类型数据之“类方法”研究
  17. React - 环境准备
  18. vue使用sweetalert2弹窗插件
  19. Selenium IDE的一些操作
  20. code#5 P1 报告

热门文章

  1. C++ string append方法的常用用法
  2. 设计模式之&mdash;&mdash;Memento模式
  3. 【查看】mysql 常规书写注意事项(那些坑)
  4. wget 命令大全
  5. SaltStack系列(三)之state相关介绍
  6. [py][lc]python高阶函数(匿名/map/reduce/sorted)
  7. testng日志和报告
  8. Which adidas NMD Singapore is your favorite
  9. Java之Integer源码
  10. 470. Implement Rand10() Using Rand7() (拒绝采样Reject Sampling)