You are viewing a single comment's thread. Return to all comments →
java8
java 8 beginner way int sum=0; int max=arr.get(0); for(int i=0;i<arr.size();i++){ sum+=arr.get(i); max=max>sum?max:sum; if(sum<0){ sum=0; } } Collections.sort(arr); int sumo=0; for(int i=0;i<arr.size();i++){ if(arr.get(i)>0){ sumo+=arr.get(i); } } List<Integer> li=new ArrayList<>(); li.add(max); if(arr.get(arr.size()-1)<0){ li.add(arr.get(arr.size()-1)); } else{ li.add(sumo); } return li; }
Seems like cookies are disabled on this browser, please enable them to open this website
The Maximum Subarray
You are viewing a single comment's thread. Return to all comments →
java8