You are viewing a single comment's thread. Return to all comments →
Ispired to your solution but avoiding if/else statement at all:
if/else
#include <cmath> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { int num; cin >> num; int counter = 0, maxCounter = 0; while (num) { const auto rem = num % 2; counter = (counter + rem) * rem; maxCounter = max(counter, maxCounter); num >>= 1; } cout << maxCounter << endl; return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 10: Binary Numbers
You are viewing a single comment's thread. Return to all comments →
Ispired to your solution but avoiding
if/else
statement at all: