2024-12-12 两数之和
This commit is contained in:
parent
4e6f94e2d4
commit
5257d175b4
@ -49,7 +49,17 @@
|
|||||||
//leetcode submit region begin(Prohibit modification and deletion)
|
//leetcode submit region begin(Prohibit modification and deletion)
|
||||||
class Solution {
|
class Solution {
|
||||||
public int[] twoSum(int[] nums, int target) {
|
public int[] twoSum(int[] nums, int target) {
|
||||||
|
for(int i=0;i<nums.length;i++){
|
||||||
|
int num1 = nums[i];
|
||||||
|
for(int j=i+1;j<nums.length;j++){
|
||||||
|
int num2 = nums[j];
|
||||||
|
if(num1 + num2 == target){
|
||||||
|
int[] answer = {i,j};
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//leetcode submit region end(Prohibit modification and deletion)
|
//leetcode submit region end(Prohibit modification and deletion)
|
||||||
|
Loading…
Reference in New Issue
Block a user