最接近的三数之和 _LintCode
来源:互联网 发布:使用ping命令测试网络 编辑:程序博客网 时间:2024/05/17 06:06
public class Solution { /** * @param numbers: Give an array numbers of n integer * @param target : An integer * @return : return the sum of the three integers, the sum closest target. */ public int threeSumClosest(int[] numbers, int target) { // write your code here if (numbers==null||numbers.length<=0){ return -1; } int length = numbers.length; //treemap的key是升序 Map<Integer,Integer> map = new TreeMap<Integer, Integer>(); for (int i=0;i<length-2;i++){ for (int j = i+1;j<length-1;j++){ for (int k = j+1;k<length;k++){ map.put(Math.abs(numbers[i]+numbers[j]+numbers[k]-target),numbers[i]+numbers[j]+numbers[k]); } } } for (int i:map.keySet()){ return map.get(i); } return 0; }}
阅读全文
0 0
- 最接近的三数之和 _LintCode
- 最接近的三数之和
- 最接近的三数之和
- LintCode:最接近的三数之和
- LintCode 52-最接近的三数之和
- LintCode 59 最接近的三数之和
- 【lintcode】两数之和、三数之和、最接近的三数之和、四数之和小结
- 最接近零的子数组和_LintCode
- 最接近3数之和
- [LeetCode]16 最接近的三者之和
- 59.3Sum Closest-最接近的三数之和(中等题)
- 求无序数组中三个元素相加与目标数最接近的三元素之和
- 算法爱好者——最接近的三数之和 ? 待解决
- 最接近目标的三数和
- 子数组之和_LintCode
- 最接近的数
- 最接近的数
- 最接近的数
- Rendering Problems Exception raised during rendering:
- Character Detection and Recognition 1-MSER
- IDHTTP中文乱码问题
- 简单的导航分页效果
- linux操作系统操作MySQL常用命令
- 最接近的三数之和 _LintCode
- 3105: [cqoi2013]新Nim游戏
- 数据对接—kettle使用知识8
- FPGA时序约束2
- postgresql从入门到菜鸟(二)
- 洛谷 P1060 开心的金明
- 数据对接—kettle使用知识9
- MyBatis学习总结(二)——SpringMVC+Spring4+Mybatis3集成,开发简单Web项目+源码下载
- symfony3 添加一个bundle,无法启动PHP内置服务器