knakul853

Untitled

Jun 25th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     string convertToBase7(int num) {
  4.        
  5.         if(num == 0 ) return "0";
  6.         if( num <  0 ) return "-" + convertToBase7(-num);
  7.        
  8.         string res = "";
  9.        
  10.         while( num >  0 )
  11.         {
  12.             res += to_string(num%7);
  13.             num = num/7;
  14.         }
  15.        
  16.         reverse(res.begin(), res.end());
  17.         return res;
  18.     }
  19. };
Add Comment
Please, Sign In to add comment