Skip to content

Commit 2dc82d8

Browse files
Create 0717. 1-bit and 2-bit Characters.py
1 parent 34bae79 commit 2dc82d8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#Runtime: 44 ms, faster than 94.77% of Python3 online submissions for 1-bit and 2-bit Characters.
2+
#Memory Usage: 14.1 MB, less than 90.57% of Python3 online submissions for 1-bit and 2-bit Characters.
3+
4+
class Solution:
5+
def isOneBitCharacter(self, bits: List[int]) -> bool:
6+
count_0 = 0
7+
if bits.count(0) > 1:
8+
for i in range(len(bits)):
9+
if bits[~i] == 0:
10+
count_0 += 1
11+
if count_0 == 2:
12+
if i % 2 == 1:
13+
return True
14+
else:
15+
return False
16+
if len(bits) % 2 == 1:
17+
return True
18+
return False

0 commit comments

Comments
 (0)