内卷地狱

2562. Find the Array Concatenation Value

Edit Me

Problem

2562. Find the Array Concatenation Value

Approach

This problem is very similar to quiz 4 — both use two pointers.

I made a mistake when computing the right pointer using a negative index: right = -left + 1. It's tricky to reason about with positive indices, so I switched to right = len(nums) - 1 - left.

Code

class Solution:
    def findTheArrayConcVal(self, nums: List[int]) -> int:
        sums = 0
        for left in range(len(nums)):
            right = len(nums) - 1 - left
            if left == right:
                sums += nums[left]
                break
            elif left < right:
                sums += int(str(nums[left]) + str(nums[right]))
        return sums

贡献者


这篇文章有帮助吗?

最近更新

Involution Hell© 2026 byCommunityunderCC BY-NC-SA 4.0CCBYNCSA