码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode-1029 Binary Prefix Divisible By 5(可被 5 整除的二进制前缀)

时间:2019-03-31 13:49:34      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:leetcode   Fix   前缀   turn   col   else   amp   pre   solution   

 1 class Solution
 2 {
 3     public:
 4         vector<bool> prefixesDivBy5(vector<int>& A)
 5         {
 6             vector<bool> v(A.size());
 7             int rnt = 0;
 8             for(int i = 0; i< A.size();i ++)
 9             {
10                 if(A[i]==1)
11                 {
12                     if(rnt==0)
13                         {rnt = 1;v[i] = false;}
14                     else if(rnt==1)
15                         {rnt = 3;v[i] = false;}
16                     else if(rnt==2)
17                         {rnt = 0;v[i] = true;}
18                     else if(rnt==3)
19                         {rnt = 2;v[i] = false;}
20                     else if(rnt==4)
21                         {rnt = 4;v[i] = false;}
22                 }
23                 else if(A[i]==0)
24                 {
25                     if(rnt==0)
26                         {rnt = 0;v[i] = true;}
27                     else if(rnt==1)
28                         {rnt = 2;v[i] = false;}
29                     else if(rnt==2)
30                         {rnt = 4;v[i] = false;}
31                     else if(rnt==3)
32                         {rnt = 1;v[i] = false;}
33                     else if(rnt==4)
34                         {rnt = 3;v[i] = false;}
35                 }
36             }
37             return v;
38         }
39 };

 

Leetcode-1029 Binary Prefix Divisible By 5(可被 5 整除的二进制前缀)

标签:leetcode   Fix   前缀   turn   col   else   amp   pre   solution   

原文地址:https://www.cnblogs.com/Asurudo/p/10630798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!