C++ 3ms Easy Solution T_T


  • 0
    W
    class Solution {
    public:
    	string convertToBase7(int num) {
    		string result;
    		bool bNegative = num >= 0 ? false : true;
    		do {
    			result += to_string(abs(num % 7));
    			num /= 7;
    		} while (num);
    		result += bNegative ? "-" : "";
    		reverse(result.begin(), result.end());
    		return result;
    	}
    };
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.