Leetcode 504 Solution
This article provides solution to leetcode question 504 (base-7)
Access this page by simply typing in "lcs 504" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/base-7
Solution
class Solution {
public:
string convertToBase7(int num) {
if (num == 0)
return "0";
else if (num < 0)
return "-" + convertToBase7(-num);
string res;
while (num)
{
res += (num % 7) + '0';
num /= 7;
}
reverse(res.begin(), res.end());
return res;
}
};