【Leetcode_easy】717. 1-bit and 2-bit Characters
problem
717. 1-bit and 2-bit Characters
题意:
solution1:
class Solution { public: bool isOneBitCharacter(vector<int>& bits) { int i=0; while(i<bits.size()-1) { if(bits[i]==0) i+=1; else i+=2; } return i==bits.size()-1; } };
solution2:根据数组的特性计算。
class Solution { public: bool isOneBitCharacter(vector<int>& bits) { int i=0, n = bits.size(); while(i<n-1) { //if(bits[i]==0) i+=1; //else i+=2; i += bits[i]+1; } return i==n-1; } };
参考
1. Leetcode_easy_717. 1-bit and 2-bit Characters;
2. Grandyang;
完
各美其美,美美与共,不和他人作比较,不对他人有期待,不批判他人,不钻牛角尖。
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/