class Solution { public: string findDigitsInBinary(int n) { string ans; if (n == 0) return "0";
while (n > 0) {
int rem = n % 2;
ans.push_back((char)('0' + rem));
n /= 2;
}
reverse(ans.begin(), ans.end());
return ans;
}
};
Aucun commentaire:
Enregistrer un commentaire