본문 바로가기
Problem Solving/LeetCode

[LeetCode] 717. 1-bit and 2-bit Characters - Java

by graycode 2026. 10. 3.

• 문제 링크

 

1-bit and 2-bit Characters - LeetCode

Can you solve this real interview question? 1-bit and 2-bit Characters - 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). Given a binary array bits that

leetcode.com

 

• 풀이 코드

public class Solution {

    public boolean isOneBitCharacter(int[] bits) {
        int i = 0, n = bits.length - 1;
        while (i < n) i += bits[i] == 0 ? 1 : 2;

        return i == n;
    }

}

댓글