[C++] Clean Code


  • 0
    class Solution {
    public:
        bool isOneBitCharacter(vector<int>& bits) {
            int n = bits.size();
            if (n == 0) return false;
            vector<bool> valid(n);
            for (int i = 0; i < n; i++) {
                valid[i] = !bits[i] && (i == 0 || valid[i - 1]) || i > 0 && bits[i - 1] && (i == 1 || valid[i - 2]);
            }
    
            return valid[n - 1] && (n == 1 || valid[n - 2]);
        }
    };
    

Log in to reply
 

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