更新0018JAVA版本
用例有一个是[1000000000,1000000000,1000000000,1000000000] -294967296 如果用int会越界,所以修改为long
This commit is contained in:
parent
23cc66346c
commit
889256a378
|
|
@ -153,7 +153,7 @@ class Solution {
|
||||||
int left = j + 1;
|
int left = j + 1;
|
||||||
int right = nums.length - 1;
|
int right = nums.length - 1;
|
||||||
while (right > left) {
|
while (right > left) {
|
||||||
int sum = nums[i] + nums[j] + nums[left] + nums[right];
|
long sum = (long) nums[i] + nums[j] + nums[left] + nums[right];
|
||||||
if (sum > target) {
|
if (sum > target) {
|
||||||
right--;
|
right--;
|
||||||
} else if (sum < target) {
|
} else if (sum < target) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue