Chinaunix首页 | 论坛 | 博客
  • 博客访问: 265280
  • 博文数量: 88
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 840
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-20 21:13
文章分类

全部博文(88)

文章存档

2022年(1)

2017年(1)

2016年(2)

2015年(1)

2014年(83)

分类: Java

2016-11-27 16:36:33


点击(此处)折叠或打开

  1. public class Solution {
  2.     public int[] twoSum(int[] nums, int target) {
  3.         
  4.         if(nums.length < 2)
  5.         {
  6.             return null;
  7.         }
  8.         
  9.         int [] result = new int[2];
  10.         
  11.         for (int i =0 ; i <= nums.length - 1; ++i )
  12.         {
  13.             for(int j = i+1; j <= nums.length -1; ++j)
  14.             {
  15.                 if(nums[i] + nums[j] == target)
  16.                 {
  17.                     result[0] = i;
  18.                     result[1] = j;
  19.                     return result;
  20.                 }
  21.             }
  22.         }
  23.         
  24.         return null;
  25.     }
  26. }


阅读(874) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~