Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MaxSubArraySum {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int[] a = {1, -3, 2, 1,-1};
- int result = maxSumSubarray(a);
- System.out.println(result);
- }
- public static int maxSumSubarray(int[] A){
- int n = A.length;
- int local_max = 0;
- int global_max = Integer.MIN_VALUE;
- for(int i = 0; i < n; i++){
- int current = A[i];
- local_max = Math.max(current, current + local_max);
- if(local_max > global_max){
- global_max = local_max;
- }
- }
- return global_max;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement