Advertisement
Guest User

Untitled

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