파비의 매일매일 공부기록

2023.05.17 Today's Challenge 본문

Problem Solving/LeetCode

2023.05.17 Today's Challenge

fabichoi 2023. 5. 17. 23:45

https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list/

 

Maximum Twin Sum of a Linked List - LeetCode

Can you solve this real interview question? Maximum Twin Sum of a Linked List - In a linked list of size n, where n is even, the ith node (0-indexed) of the linked list is known as the twin of the (n-1-i)th node, if 0 <= i <= (n / 2) - 1. * For example, if

leetcode.com

오늘도 리스트 문제

class Solution:
    def pairSum(self, head: Optional[ListNode]) -> int:
        cur = head
        val = []
        while cur:
            val.append(cur.val)
            cur = cur.next        
        i = 0
        j = len(val) - 1
        res = 0
        while(i < j):
            res = max(res, val[i] + val[j])
            i += 1
            j -= 1
        return res
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

2023.05.19 Today's Challenge  (0) 2023.05.19
2023.05.18 Today's Challenge  (0) 2023.05.18
2023.05.16 Today's Challenge  (0) 2023.05.16
2023.05.15 Today's Challenge  (1) 2023.05.15
2023.05.14 Today's Challenge  (0) 2023.05.14
Comments