Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string convertToBase7(int num) {
- if(num == 0 ) return "0";
- if( num < 0 ) return "-" + convertToBase7(-num);
- string res = "";
- while( num > 0 )
- {
- res += to_string(num%7);
- num = num/7;
- }
- reverse(res.begin(), res.end());
- return res;
- }
- };
Add Comment
Please, Sign In to add comment