3Sum Closest
来源:互联网 发布:whatsapp是什么软件 编辑:程序博客网 时间:2024/04/28 05:34
public int threeSumClosest(int[] num, int target) { // Start typing your Java solution below // DO NOT write main() function if(num.length < 3) return Integer.MIN_VALUE; Arrays.sort(num); int result = num[0] + num[1] + num[2];//pay attention here to initiate the result for(int i = 0; i < num.length - 2; i++){ int start = i + 1; int end = num.length - 1; while(start < end) { int sum = num[i] + num[start] + num[end]; if(Math.abs(sum - target) < Math.abs(result - target)) result = sum; if(sum == target) { result = target; return result; }else if(sum < target) { start++; }else { end--; } } } return result; }
- 3 Sum & 3 Sum Closest
- 【Leetcode】3Sum Closest (Sum)
- LeetCode: 3 Sum Closest
- 3Sum Closest
- leetcode - 3 sum closest
- leetcode 3Sum Closest
- LeetCode: 3Sum Closest
- [Leetcode]3Sum Closest
- Leetcode: 3SUM Closest
- LeetCode 3Sum Closest
- [Leetcode] 3Sum Closest
- leetcode002:3sum closest
- LeetCode : 3Sum Closest
- LeetCode 3Sum Closest
- 3Sum Closest
- 3Sum Closest
- 3Sum Closest
- [LeetCode] 3Sum Closest
- 【设计模式】学习笔记16:代理模式之虚拟代理(实现CD封面加载器)
- DeDecms 友情链接
- Oracle分布式系统数据复制技术——概念篇
- HDU 4617 Weapon (三维计算几何)
- 开发R程序包之忍者篇[http://cos.name/2011/05/write-r-packages-like-a-ninja/]
- 3Sum Closest
- How do human sketch objects?
- 好看的动漫 壁纸
- 一台服务器配置多WebSite
- delphi读取excel的两种方法
- C语言用结构体实现位段
- hibernate执行sql
- 庆祝微博开通
- 不成为阴谋与阳谋的牺牲品(上)