Advertisement
nikunjsoni

1869

May 24th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     bool checkZeroOnes(string s) {
  4.         int max1, max0, c1, c0;
  5.         max1 = max0 = c1 = c0 = 0;
  6.         for(char c: s){
  7.             if(c=='0'){
  8.                 c0++;
  9.                 max1 = max(max1, c1);
  10.                 c1 = 0;
  11.             }
  12.             else{
  13.                 c1++;
  14.                 max0 = max(max0,  c0);  
  15.                 c0=0;
  16.             }
  17.         }
  18.         max1 = max(max1, c1);
  19.         max0 = max(max0, c0);
  20.         if(max1 > max0) return true;
  21.         return false;
  22.     }
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement