leetcode算法题--1比特与2比特字符

原题链接:https://leetcode-cn.com/problems/1-bit-and-2-bit-characters/

class Solution {
public:
    bool isOneBitCharacter(vector<int>& bits) {
        int n = bits.size();
        int i = 0;
        while (i < n - 1) {
            if (bits[i] == 1) i += 2;
            else  i += 1;
        }
        return i == n - 1;
    }
};

你可能感兴趣的:(Algorithm,leetcode,算法,职场和发展)