Leetcode-1029 Binary Prefix Divisible By 5(可被 5 整除的二进制前缀)
Posted asurudo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode-1029 Binary Prefix Divisible By 5(可被 5 整除的二进制前缀)相关的知识,希望对你有一定的参考价值。
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 整除的二进制前缀)的主要内容,如果未能解决你的问题,请参考以下文章
leetcode1029. Two City Scheduling