Last active
December 31, 2015 03:39
-
-
Save czxttkl/7929509 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestConSum { | |
public static void main(String... args) { | |
int[] arr = new int[]{-2,11,-4,13, -9, -10,99}; | |
int negsum = 0; | |
int maxsum = 0; | |
for (int i = 0; i < arr.length; i++) { | |
if (arr[i] < 0) { | |
negsum += arr[i]; | |
continue; | |
} | |
if (arr[i] > 0) { | |
maxsum = max(maxsum + negsum + arr[i], arr[i], maxsum); | |
negsum = 0; | |
} | |
} | |
System.out.println(maxsum); | |
} | |
private static int max (int a, int b, int c) { | |
int tmp = a > b? a : b; | |
return tmp > c? tmp : c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
public class Test {
}