We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6114e50 commit 9610446Copy full SHA for 9610446
2130-maximum-twin-sum-of-a-linked-list.js
@@ -0,0 +1,27 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * function ListNode(val, next) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.next = (next===undefined ? null : next)
6
+ * }
7
+ */
8
9
+ * @param {ListNode} head
10
+ * @return {number}
11
12
+const pairSum = function(head) {
13
+ const arr = []
14
+ let cur = head
15
+
16
+ while(cur) {
17
+ arr.push(cur.val)
18
+ cur = cur.next
19
+ }
20
21
+ let res = 0
22
+ for(let i = 0, n = arr.length; i < n / 2; i++) {
23
+ res = Math.max(res, arr[i] + arr[n - 1 - i])
24
25
26
+ return res
27
+};
0 commit comments