C++, no need to check from the beginning. Just check the end


  • 0
    Z
        bool isOneBitCharacter(vector<int>& bits) {
            int size = bits.size();
            if(size < 2 || 0 == bits[size - 2])    return true;
            int cnt = 1;
            for(int i = size - 3; i >= 0 && bits[i]; --i) {
                ++cnt;
            }
            return 0 == cnt % 2;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.