Skip to content

Commit a621718

Browse files
authored
Create Solution.java
1 parent 711fa62 commit a621718

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

solution/0504.Base 7/Solution.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public String convertToBase7(int num) {
3+
if (num == 0) {
4+
return "0";
5+
}
6+
if (num < 0) {
7+
return "-" + convertToBase7(-num);
8+
}
9+
StringBuilder sb = new StringBuilder();
10+
while (num != 0) {
11+
sb.append(num % 7);
12+
num /= 7;
13+
}
14+
return sb.reverse().toString();
15+
}
16+
}

0 commit comments

Comments
 (0)