Skip to content

Commit a7a62c0

Browse files
committed
Time: 0 ms (100.00%), Space: 5.9 MB (82.13%) - LeetHub
1 parent 638684f commit a7a62c0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

base-7/base-7.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
string convertToBase7(int num) {
4+
int x = abs(num);
5+
string ans = "";
6+
do{
7+
int rem = x % 7;
8+
x /= 7;
9+
ans += to_string(rem);
10+
}while(x);
11+
12+
if(num < 0)
13+
ans += "-";
14+
reverse(ans.begin(), ans.end());
15+
16+
return ans;
17+
}
18+
};

0 commit comments

Comments
 (0)