Skip to content

Latest commit

 

History

History
19 lines (17 loc) · 505 Bytes

2511.md

File metadata and controls

19 lines (17 loc) · 505 Bytes

2511. Maximum Enemy Forts That Can Be Captured

Solution 1 (time O(n), space O(1))

class Solution(object):
    def captureForts(self, forts):
        """
        :type forts: List[int]
        :rtype: int
        """
        ans, pre = 0, -1
        for i, fort in enumerate(forts):
            if fort == -1 or fort == 1:
                if pre >= 0 and fort != forts[pre]:
                    ans = max(ans, i - pre - 1)
                pre = i
        return ans