Skip to content

Commit 4a9e077

Browse files
authored
Create maximum-enemy-forts-that-can-be-captured.py
1 parent e930f36 commit 4a9e077

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# array, two pointers
5+
class Solution(object):
6+
def captureForts(self, forts):
7+
"""
8+
:type forts: List[int]
9+
:rtype: int
10+
"""
11+
result = left = 0
12+
for right in xrange(len(forts)):
13+
if not forts[right]:
14+
continue
15+
if forts[right] == -forts[left]:
16+
result = max(result, right-left-1)
17+
left = right
18+
return result

0 commit comments

Comments
 (0)