Skip to content

Commit 68f0ec3

Browse files
author
Tomislav Marinkovic
committed
Refactor
1 parent fb39e17 commit 68f0ec3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/array/algorithn/MaximumSubArray.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ public int[] run(Input input) {
1717
start(data.length);
1818

1919
int currentMaximum = Integer.MIN_VALUE;
20-
int maximum = 0, startIndex = 0, endIndex = 0, s = 0;
20+
int sum = 0, startIndex = 0, endIndex = 0, tempStartIndex = 0;
2121

2222
for (int i = 0; i < data.length; i++) {
23-
maximum += data[i];
23+
sum += data[i];
2424

25-
if (currentMaximum < maximum) {
26-
currentMaximum = maximum;
27-
startIndex = s;
25+
if (currentMaximum < sum) {
26+
currentMaximum = sum;
27+
startIndex = tempStartIndex;
2828
endIndex = i;
2929
}
3030

31-
if (maximum < 0) {
32-
maximum = 0;
33-
s = i + 1;
31+
if (sum < 0) {
32+
sum = 0;
33+
tempStartIndex = i + 1;
3434
}
3535
}
3636
done();

0 commit comments

Comments
 (0)