加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

717. 1-bit and 2-bit Characters

发布时间:2020-12-14 04:48:06 所属栏目:大数据 来源:网络整理
导读:1 static int wing= []() 2 { 3 std::ios::sync_with_stdio( false ); 4 cin.tie(NULL); 5 return 0 ; 6 }(); 7 8 class Solution 9 { 10 public : 11 bool isOneBitCharacter(vector int bits) 12 { 13 int sz= bits.size(); 14 int i= 0 ; 15 while (isz-
 1 static int wing=[]()
 2 {
 3     std::ios::sync_with_stdio(false);
 4     cin.tie(NULL);
 5     return 0;
 6 }();
 7 
 8 class Solution 
 9 {
10 public:
11     bool isOneBitCharacter(vector<int>& bits) 
12     {
13         int sz=bits.size();
14         int i=0;
15         while(i<sz-1)
16         {
17             if(bits[i]==1)
18                 i+=2;
19             else
20                 i+=1;
21         }
22         return i==sz-1;
23     }
24 };

这个题,从前向后扫,只要当前位为1,则不用管下一位是啥,必然要构成2位,所以当前位为1时,直接跳至下下个位置。

只有当末尾0前面有个落单的1时,末尾才不能为单,此时扫描到那个1的时候,加上2,i变为了sz

当末尾0前面不为非规则数字,i 必然不会跳过最后的0,会指向那个0,即i==sz-1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读