MCPcopy Create free account
hub / github.com/Sugapriyan-P-K/blind75 / maxSubArr

Method maxSubArr

Arrays/5maximumSubarray/MaximumSubarray.java:2–13  ·  view source on GitHub ↗
(int[] nums)

Source from the content-addressed store, hash-verified

1public class Solution {
2 public static int maxSubArr(int[] nums) {
3 int maxSub = nums[0],
4 curSum = 0;
5 for (int i = 0; i < nums.length; i++) {
6 if (curSum < 0) {
7 curSum = 0;
8 }
9 curSum += nums[i];
10 maxSub = Math.max(curSum, maxSub);
11 }
12 return maxSub;
13 }
14 // just for testing
15 public static void main(String[] args) {
16 int[] nums = { -2, 1, -3, 4, -1, 2, 1, -5, 4 };

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected