package LeetCode.contact;
import java.util.Arrays;
class Solution_1 {
public int[] twoSum(int[] nums, int target) {
int arr[] = new int[2];
boolean isFlag = true;
while(isFlag){
for(int i = 0; i < nums.length; i ++){
for(int j = i+1; j <nums.length; j++){
if(nums[i] + nums[j] == target){
arr[0] = i;
arr[1] = j;
isFlag = false;
break;
}
}
}}
return arr;
}
}
public class leetcode_1 {
public static void main(String[] args){
int []arr = new int[] {3,2,4};
Solution_1 sol = new Solution_1();
int []a = sol.twoSum(arr, 6);
System.out.println(Arrays.toString(a));
}
}
LeetCode_1:两数之和:Java
最新推荐文章于 2024-11-04 12:20:00 发布