Leetcode 717. 1-bit and 2-bit Characters

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

《Leetcode 717. 1-bit and 2-bit Characters》 1-bit and 2-bit Characters

2. Solution

class Solution {
public:
    bool isOneBitCharacter(vector<int>& bits) {
        int step = 1;
        int index = 0;
        while(index < bits.size()) {
            step = bits[index]==1?2:1;
            index += step;
        }
        return step == 1;
    }
};

Reference

  1. https://leetcode.com/problems/1-bit-and-2-bit-characters/description/
    原文作者:SnailTyan
    原文地址: https://www.jianshu.com/p/3f62fa000a23
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞