1. 程式人生 > >leetcode717+判斷bit陣列最後一位是否為0,貪心

leetcode717+判斷bit陣列最後一位是否為0,貪心

https://leetcode.com/problems/1-bit-and-2-bit-characters/description/

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