2024-12-12 两数之和

This commit is contained in:
liangjinglin 2024-12-12 22:37:07 +08:00
parent 4e6f94e2d4
commit 5257d175b4

View File

@ -49,7 +49,17 @@
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
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)