LetsNum& operator++(int) { int carry = 1; for (deque<char>::iterator it = num.begin(); it != num.end(); it++) { carry += *it - '0'; *it = carry % 10 + '0'; carry /= 10; } if (carry) { num.push_back(carry + '0'); } return *this; }
// only 0/1 supported LetsNum& operator+=(constint& n) { if (!n) { return *this; } (*this)++; return *this; }
// only 0/1 supported LetsNum& operator+=(constchar& c) { *this += c - '0'; return *this; }
// only <<1 supported LetsNum& operator<<=(constint&) { int carry = 0; for (deque<char>::iterator it = num.begin(); it != num.end(); it++) { carry += (*it - '0') * 2; *it = carry % 10 + '0'; carry /= 10; } if (carry) { num.push_back(carry + '0'); } return *this; }
// only >>1 supported LetsNum& operator>>=(constint&) { int mod = 0; for (deque<char>::reverse_iterator it = num.rbegin(); it != num.rend(); it++) { mod = mod * 10 + (*it - '0'); *it = mod / 2 + '0'; mod %= 2; } if (*num.rbegin() == '0') { num.pop_back(); } return *this; }
''' LastEditTime: 2026-02-26 23:59:25 ''' """ 1101 1110 111 1000 100 10 1 """ classSolution: defnumSteps(self, s: str) -> int: a = int(s, 2) ans = 0 while a != 1: if a % 2: a += 1 else: a //= 2 ans += 1 # print(a) return ans