Skip to content

Commit 17e39cf

Browse files
authored
Create ant-on-the-boundary.py
1 parent 35c9d5d commit 17e39cf

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Python/ant-on-the-boundary.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# prefix sum
5+
class Solution(object):
6+
def returnToBoundaryCount(self, nums):
7+
"""
8+
:type nums: List[int]
9+
:rtype: int
10+
"""
11+
result = curr = 0
12+
for x in nums:
13+
curr += x
14+
if curr == 0:
15+
result += 1
16+
return result

0 commit comments

Comments
 (0)