Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package week1;
- /*
- * @author Tanzim Ibn Patowary
- * Created Apr 9, 2020 11:14:19 AM
- */
- public class MaxmumSub {
- public static int maxSubArray(int[] nums) {
- int sum = 0;
- int bestsum = 0;
- for (int i : nums) {
- sum = Math.max(0, i+sum);
- bestsum = Math.max(bestsum, sum);
- }
- return bestsum;
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int my[] = {-2,1,-3,4,-1,2,1,-5,4};
- System.out.println(maxSubArray(my));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement