Posted on

Description

Submission

class Solution {
    int n;

    bool dfs(vector<int>& bits, int idx) {

        if(idx == n - 1) {
            return true;
        }
        if(idx == n - 2) {
            if(bits[idx] == 0) return true;
            return false;
        }

        if(bits[idx] == 1) { 
            if(!dfs(bits, idx + 2)) return false;
        } else {
            if(!dfs(bits, idx + 1)) return false;
        }

        return true;
    }
public:
    bool isOneBitCharacter(vector<int>& bits) {
        n = bits.size();

        return dfs(bits, 0);
    }
};

// 0 10 11

Leave a Reply

Your email address will not be published. Required fields are marked *