-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy path2130.java
More file actions
30 lines (27 loc) · 782 Bytes
/
2130.java
File metadata and controls
30 lines (27 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public int pairSum(ListNode head) {
List<Integer> l = new ArrayList<>();
ListNode current = head;
while(current != null){
l.add(current.val);
current = current.next;
}
int max = Integer.MIN_VALUE, n = l.size();
for(int i=0;i<=(n/2)-1;i++){
if(l.get(i)+l.get(n-i-1) > max){
max = l.get(i)+l.get(n-i-1);
}
}
return max;
}
}