Skip to content

Instantly share code, notes, and snippets.

@vamsitallapudi
Created March 12, 2024 06:27
Show Gist options
  • Save vamsitallapudi/8c706c63bb8bec45deab2a438053b54a to your computer and use it in GitHub Desktop.
Save vamsitallapudi/8c706c63bb8bec45deab2a438053b54a to your computer and use it in GitHub Desktop.
class Solution {
public int maxSubArray(int[] nums) {
int currMax = nums[0];
int overallMax = nums[0];
for(int i = 1; i< nums.length;i++) {
currMax = Math.max(nums[i], currMax+nums[i]);
overallMax = Math.max(currMax, overallMax);
}
return overallMax;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment