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
출처 : leetCode
'LeetCode > Easy' 카테고리의 다른 글
[Java] LeetCode 258 : Add Digits (0) | 2021.05.12 |
---|---|
[Java] LeetCode 67 : Add Binary (0) | 2021.05.12 |
[Java] LeetCode 953 : Verifying an Alien Dictionary (0) | 2021.04.21 |
[Java] LeetCode 874 : Walking Robot Simulation (0) | 2021.04.17 |
[Java] LeetCode 1518 : Water Bottles (0) | 2021.04.17 |