首页 > 其他 > 详细

[Leetcode]--Two Sum

时间:2014-01-25 22:33:18      阅读:423      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
public class Solution {
    public int[] twoSum(int[] numbers, int target) {
        // IMPORTANT: Please reset any member data you declared, as
        // the same Solution instance will be reused for each test case.
        
        int[] results = new int[2];
         
         for(int i = 0; i < numbers.length - 1; i++){
             for(int j = i + 1; j < numbers.length; j++){
                 if(numbers[i] + numbers[j] == target){
                     results[0] = i + 1;
                     results[1] = j + 1;
                     return results;
                 }
             }
         }
         return results;
        
    }
}
bubuko.com,布布扣

[Leetcode]--Two Sum

原文:http://www.cnblogs.com/RazerLu/p/3533416.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!