@Test public void algoTest(){ algo=new ContigousSubArraySumKadane(); algo.subSum(input); }
public int subSum(int[] nums) { if(nums.length==0){return 0;} int total=nums[0], maxTotal=nums[0]; for(int i=1; i<nums.length; i++){ total = (total>0) ? total+nums[i] : nums[i]; System.out.println("total sum: "+ total); maxTotal = (maxTotal>total) ? maxTotal : total; } System.out.println(maxTotal); return maxTotal; }
ContigousSubArraySumKadane { public int subSum(int[] nums) { if(nums.length==0){return 0;} int total=nums[0], maxTotal=nums[0]; for(int i=1; i<nums.length; i++){ total = (total>0) ? total+nums[i] : nums[i]; System.out.println("total sum: "+ total); maxTotal = (maxTotal>total) ? maxTotal : total; } System.out.println(maxTotal); return maxTotal; } }
ContigousSubArraySumKadane { public int subSum(int[] nums) { if(nums.length==0){return 0;} int total=nums[0], maxTotal=nums[0]; for(int i=1; i<nums.length; i++){ total = (total>0) ? total+nums[i] : nums[i]; System.out.println("total sum: "+ total); maxTotal = (maxTotal>total) ? maxTotal : total; } System.out.println(maxTotal); return maxTotal; }  }
ContigousSubArraySumKadane { public int subSum(int[] nums) { if(nums.length==0){return 0;} int total=nums[0], maxTotal=nums[0]; for(int i=1; i<nums.length; i++){ total = (total>0) ? total+nums[i] : nums[i]; System.out.println("total sum: "+ total); maxTotal = (maxTotal>total) ? maxTotal : total; } System.out.println(maxTotal); return maxTotal; }  int sum(int[] input); int subSum(int[] nums); }
ContigousSubArraySumKadane { public int subSum(int[] nums) { if(nums.length==0){return 0;} int total=nums[0], maxTotal=nums[0]; for(int i=1; i<nums.length; i++){ total = (total>0) ? total+nums[i] : nums[i]; System.out.println("total sum: "+ total); maxTotal = (maxTotal>total) ? maxTotal : total; } System.out.println(maxTotal); return maxTotal; }  int sum(int[] input); int subSum(int[] nums);  }