Skip to content

Commit 26ec4cd

Browse files
committed
maximum-subarray solution
1 parent 8067902 commit 26ec4cd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

maximum-subarray/acious.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
fun maxSubArray(nums: IntArray): Int {
3+
var maxSum = nums[0]
4+
var sum = 0
5+
6+
for(num in nums) {
7+
sum = max(sum+num, num)
8+
maxSum = max(sum, maxSum)
9+
}
10+
11+
return maxSum
12+
}
13+
}

0 commit comments

Comments
 (0)