forked from Vishal-Aggarwal0305/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlongestContiguous.py
45 lines (42 loc) · 923 Bytes
/
longestContiguous.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
s = "111000"
list1 = []
list2 = []
count = 0
for i in s:
if i == "1":
count +=1
else:
list1.append(count)
count = 0
list1.append(count)
count = 0
for i in s:
if i == "0":
count +=1
else:
list2.append(count)
count = 0
list2.append(count)
print(max(list1))
print(max(list2))
if max(list2)<=max(list1):
print("True")
else:
print("False")
# class Solution:
# def checkZeroOnes(self, s: str) -> bool:
# best_one, best_zero, current_one, current_zero = 0, 0, 0, 0
#
# for i in s:
# if i == "1":
# current_zero = 0
# current_one += 1
# else:
# current_zero += 1
# current_one = 0
#
# best_one = max(best_one, current_one)
# best_zero = max(best_zero, current_zero)
#
# return best_one > best_zero
# Fn + F5