Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1.  class Solution {
  2.      public int maxSubArray(int[] A) {
  3.          int max = Integer.MIN_VALUE, sum = 0;
  4.          for (int i = 0; i < A.length; i++) {
  5.              if (sum < 0)
  6.                  sum = A[i];
  7.              else
  8.                  sum += A[i];
  9.              if (sum > max)
  10.                  max = sum;
  11.          }
  12.          return max;
  13.      }
  14.  
  15.      public static void main(String[] args) {
  16.          Solution solution = new Solution();
  17.          int sol= solution.maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4});
  18.          System.out.println(sol);
  19.      }
  20.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement