Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int maxSubArray(int[] nums) {
- Integer current_sum = Integer.MIN_VALUE + 10001;
- Integer best_sum = Integer.MIN_VALUE;
- for (int i = 0; i < nums.length; i++) {
- if (current_sum > nums[i] || ((current_sum + nums[i]) > nums[i])) {
- current_sum += nums[i];
- }
- else {
- current_sum = nums[i];
- }
- if (current_sum > best_sum) {
- best_sum = current_sum;
- }
- }
- return best_sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement