Skip to content

Commit 0aaae9a

Browse files
authored
Fixed integer overflow errors (kamyu104#90)
There are some new testcases coming. And one of them requires type of larger size...
1 parent 39208fd commit 0aaae9a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

C++/split-array-largest-sum.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
class Solution {
55
public:
66
int splitArray(vector<int>& nums, int m) {
7-
int left = 0, right = 0;
7+
long long left = 0, right = 0;
88
for (const auto& num : nums) {
9-
left = max(left, num);
9+
if (left < num) left = num;
1010
right += num;
1111
}
1212

@@ -23,7 +23,8 @@ class Solution {
2323

2424
private:
2525
bool canSplit(vector<int>& nums, int m, int sum) {
26-
int cnt = 1, curr_sum = 0;
26+
int cnt = 1;
27+
long long curr_sum = 0;
2728
for (const auto& num : nums) {
2829
curr_sum += num;
2930
if (curr_sum > sum) {

0 commit comments

Comments
 (0)