Leetcode 504 Base 7 Solution in java | Hindi Coding Community

0


 

Given an integer num, return a string of its base 7 representation.


Example 1:


Input: num = 100

Output: "202"



public String convertTo7(int num) {
if (num < 0)
return '-' + convertTo7(-num);
if (num < 7)
return num + "";
return convertTo7(num / 7) + num % 7;
}



Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !