Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package week1;
- /*
- * @author Tanzim Ibn Patowary
- * Created Apr 9, 2020 3:50:54 PM
- */
- public class MaxSum {
- public static int maxSubArray(int[] nums) {
- int startpoint = nums[0];
- int storesum = 0;
- for (int i = 0; i < nums.length; i++) {
- storesum = storesum + nums[i];
- if (startpoint < storesum) {
- startpoint = storesum;
- }
- if (storesum < 0) {
- storesum = 0;
- }
- }
- return storesum;
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int myArray[] = { -2, 1, -3, 4, -1, 2, 1, -5, 4 };
- System.out.println(maxSubArray(myArray));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement