2571. Find the Pivot Integer
My accepted Python solution to LeetCode problem 2571, Find the Pivot Integer, running in 7ms.
- Difficulty: Easy
- Python
- Runtime 7ms
- Memory 17.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 7ms, memory 17.5MB, accepted 2026-01-01.
class Solution:
def pivotInteger(self, n: int) -> int:
total = n * (n + 1) // 2
left_sum = 0
for x in range(1, n + 1):
left_sum += x
right_sum = total - left_sum + x
if left_sum == right_sum:
return x
return -1