LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 44ms, memory 17.2MB, accepted 2026-01-01.

python
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

Source