Skip to content
On this page

2130. 链表最大孪生和

原题链接:LeetCode 2130. 链表最大孪生和

题解代码

javascript
var pairSum = function(head) {
  const arr = []
  while (head) {
    arr.push(head.val)
    head = head.next
  }
  let left = 0, right = arr.length - 1, max = - Infinity
  while (left < right) {
    max = Math.max(max, arr[left] + arr[right])
    left ++
    right --
  }
  return max
};

技术文档集合