3311. Ant on the Boundary
My accepted Python solution to LeetCode problem 3311, Ant on the Boundary, running in 44ms.
- Difficulty: Easy
- Python
- Runtime 44ms
- Memory 17.2MB
- 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 44ms, memory 17.2MB, accepted 2026-01-01.
class Solution:
def returnToBoundaryCount(self, nums: List[int]) -> int:
position = 0
count = 0
for num in nums:
position += num
if position == 0:
count += 1
return count