LeetCode/Easy
[Java] LeetCode 717 : 1-bit and 2-bit Characters
새우버거♬
2021. 4. 21. 04:40
LeetCode # 717
Example 1:
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.
Example 2:
Input:
bits = [1, 1, 1, 0]
Output: False
Explanation: The only way to decode it is two-bit character and one-bit character. So the last character is one-bit character.
Note:
- 1 <= len(bits) <= 1000.
- bits[i] is always 0 or 1.
Solution #1 (0ms)
class Solution {
public boolean isOneBitCharacter(int[] bits) {
int i = 0;
while (i < bits.length - 1) {
i += bits[i] == 1 ? 2 : 1;
}
return i == bits.length - 1;
}
}
Result #1
More Algorithm!
👇👇
github.com/ggujangi/ggu.leet-code
ggujangi/ggu.leet-code
LeetCode, Java. Contribute to ggujangi/ggu.leet-code development by creating an account on GitHub.
github.com
출처 : leetCode