aboutsummaryrefslogtreecommitdiff
path: root/three_consecutive_odds.py
blob: 7abb6bb20aa42a40e5737bf1c0f508af9456d308 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 1550. Three Consecutive Odds

"""
given an integer array 'arr', return true if there are three consecutive odd
numbers in the array. otherwise, return false
"""


class Solution(object):
    def threeConsecutiveOdds(self, arr):
        """
        :type arr: List[int]
        :rtype: bool
        """
        cnt = 0
        for i in arr:
            if i % 2 != 0:
                cnt += 1
                if cnt == 3:
                    return True
            else:
                cnt = 0
        return False


if __name__ == "__main__":
    obj = Solution()
    print(obj.threeConsecutiveOdds(arr=[2, 6, 4, 1]))
    print(obj.threeConsecutiveOdds(arr=[1, 2, 34, 3, 4, 5, 7, 23, 12]))