package com.lyh.leetCode;
import java.util.Arrays;
public class Solution {
public int[] twoSum(int[] nums,int target) {
int len = nums.length;
for (int i = 0; i < len - 1; i++) {
for (int j = i + 1; j < len; j++) {
if (nums[i] + nums[j] == target) {
int[] c = new int[]{i, j};
System.out.println(Arrays.toString(c));
}
}
}
return null;
// throw new IllegalArgumentException("No two sum solution");
}
public static void main(String[] args) {
Solution a = new Solution();
int[] b = {1,2,3,4};
// System.out.println(Arrays.toString(b));
int l=4;
a.twoSum(b,l);
}
}
leetCode
最新推荐文章于 2024-10-19 16:37:08 发布