https://leetcode.com/problems/base-7/description/
Solution 1.
string convertToBase7(int num) {
if(num == 0) return "0";
string res;
int x = abs(num);
while(x) {
res = to_string(x % 7) + res;
x /= 7;
}
return (num>0 ? "":"-")+res;
}
No comments:
Post a Comment