class Solution {
public int[] findNumbersWithSum(int[] nums, int target) {
Set<Integer> set = new HashSet<>();
for (int x : nums) {
int y = target - x;
if (set.contains(y)) {
int[] res = new int[]{x, y};
return res;
}
set.add(x);
}
return null;
}
}
Acwing 75. 和为S的两个数字
最新推荐文章于 2024-07-27 17:56:15 发布