Saturday, October 28, 2017

717. 1-bit and 2-bit Characters

    bool isOneBitCharacter(vector<int>& bits) {
        if(bits.back() == 1) return false;
        if(bits.size() == 1) return true;
        for(int i=0; i<bits.size();) {
            if(bits[i] == 1) i += 2;
            else i++;
            if(i == bits.size()-1) return true;
        }
        return false;
    }

No comments:

Post a Comment