leetcode 1. two sum

来源:互联网 发布:淘宝卖红酒 编辑:程序博客网 时间:2024/05/18 03:22

public class Solution {
    public int[] twoSum(int[] nums, int target) {
 for(int i = 0;i<nums.length;i++){
   for(int j = i+1;j<nums.length;j++){
    if(nums[i]+nums[j] == target){
     int[] a = {i,j};
     return a;
     
    }
   }
  }
  
  throw new IllegalArgumentException("No two sum solution");
    }
}
0 0
原创粉丝点击