- SW Expert Academy
- Real or Not? NLP with Disaster Tweets
- 더현대서울 맛집
- AI 경진대회
[leetCode] 717. 1-bit and 2-bit Characters (Python) 본문
[leetCode] 717. 1-bit and 2-bit Characters (Python)솜씨좋은장씨 2021. 1. 17. 22:58
We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11).
Now given a string represented by several bits. Return whether the last character must be a one-bit character or not. The given string will always end with a zero.
Input: bits = [1, 0, 0] Output: True Explanation: The only way to decode it is two-bit character and one-bit character. So the last character is one-bit character.
Input: bits = [1, 1, 1, 0] Output: False Explanation: The only way to decode it is two-bit character and two-bit character. So the last character is NOT one-bit character.
- 1 <= len(bits) <= 1000.
- bits[i] is always 0 or 1.
class Solution: def isOneBitCharacter(self, bits: List[int]) -> bool: i = 0 while i < len(bits)-1: if bits[i] == 0: i+=1 else: i+=2 return i == len(bits)-1
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
|[leetCode] 1592. Rearrange Spaces Between Words (Python) (0)||2021.01.19|
|[leetCode] 876. Middle of the Linked List (Python) (0)||2021.01.18|
|[leetCode] 717. 1-bit and 2-bit Characters (Python) (0)||2021.01.17|
|[leetCode] 908. Smallest Range I (Python) (0)||2021.01.16|
|[leetCode] 520. Detect Capital (Python) (0)||2021.01.15|
|[leetCode] 237. Delete Node in a Linked List (Python) (0)||2021.01.14|