Skip to content

Commit 35c9d5d

Browse files
authored
Create ant-on-the-boundary.cpp
1 parent e94aef8 commit 35c9d5d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

C++/ant-on-the-boundary.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// prefix sum
5+
class Solution {
6+
public:
7+
int returnToBoundaryCount(vector<int>& nums) {
8+
int result = 0, curr = 0;
9+
for (const auto& x : nums) {
10+
curr += x;
11+
if (curr == 0) {
12+
++result;
13+
}
14+
}
15+
return result;
16+
}
17+
};

0 commit comments

Comments
 (0)