美文网首页Leetcode
Leetcode 717. 1-bit and 2-bit Ch

Leetcode 717. 1-bit and 2-bit Ch

作者: SnailTyan | 来源:发表于2018-10-24 17:56 被阅读0次

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

    1. Description

    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/

    相关文章

      网友评论

        本文标题:Leetcode 717. 1-bit and 2-bit Ch

        本文链接:https://www.haomeiwen.com/subject/qhvxtqtx.html