From 889256a3781ebc8891f8a37778334f402acf362e Mon Sep 17 00:00:00 2001 From: chenwingsing <742474834@qq.com> Date: Sat, 2 Jul 2022 21:58:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B00018JAVA=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用例有一个是[1000000000,1000000000,1000000000,1000000000] -294967296 如果用int会越界,所以修改为long --- problems/0018.四数之和.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/0018.四数之和.md b/problems/0018.四数之和.md index 2146a114..99613070 100644 --- a/problems/0018.四数之和.md +++ b/problems/0018.四数之和.md @@ -153,7 +153,7 @@ class Solution { int left = j + 1; int right = nums.length - 1; 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) { right--; } else if (sum < target) {