Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MaxPodsuma {
- public static void maxPodsuma(SLL<Integer> list){
- SLLNode<Integer> tmp=list.getFirst();
- SLLNode<Integer> tmp2;
- int sum=0;
- int max=tmp.element;
- while (tmp!=null){
- sum=0;
- sum+=tmp.element;
- tmp2=tmp.succ;
- while (tmp2!=null){
- sum+=tmp2.element;
- if(sum>max){
- max=sum;
- }
- tmp2=tmp2.succ;
- }
- tmp=tmp.succ;
- }
- System.out.println(max);
- }
- public static void main(String[] args) {
- Scanner in=new Scanner(System.in);
- int n=in.nextInt();
- SLL<Integer> list=new SLL<>();
- for(int i=0;i<n;i++){
- list.insertLast(in.nextInt());
- }
- maxPodsuma(list);
- }
- }
Add Comment
Please, Sign In to add comment