-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path393.py
26 lines (21 loc) · 779 Bytes
/
393.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
class Solution:
def validUtf8(self, data: List[int]) -> bool:
def check(size):
for i in range(start+1, start + size + 1):
if i >= len(data) or (data[i] >> 6) != 0b10:
return False
return True
start = 0
while start < len(data):
first = data[start]
if (first) >> 3 == 0b11110 and check(3):
start += 4
elif (first) >> 4 == 0b1110 and check(2):
start += 3
elif (first) >> 5 == 0b110 and check(1):
start += 2
elif (first) >> 7 == 0:
start += 1
else:
return False
return True