-
Notifications
You must be signed in to change notification settings - Fork 326
/
Copy path73-1.py
27 lines (24 loc) · 867 Bytes
/
73-1.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
from typing import List
class Solution:
def validUtf8(self, data: List[int]) -> bool:
# 문자 바이트 만큼 10으로 시작 판별
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