Skip to content

Commit 54fe09b

Browse files
committed
fix: display lc problem: No.0521 java solution
No.0504.Base 7
1 parent 2bd07d7 commit 54fe09b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

solution/0500-0599/0504.Base 7/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@
4343
<!-- 这里可写当前语言的特殊实现逻辑 -->
4444

4545
```java
46+
class Solution {
47+
public String convertToBase7(int num) {
48+
if (num == 0) {
49+
return "0";
50+
}
51+
if (num < 0) {
52+
return "-" + convertToBase7(-num);
53+
}
54+
StringBuilder sb = new StringBuilder();
55+
while (num != 0) {
56+
sb.append(num % 7);
57+
num /= 7;
58+
}
59+
return sb.reverse().toString();
60+
}
61+
}
4662

4763
```
4864

solution/0500-0599/0504.Base 7/README_EN.md

+16
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ The input will be in range of [-1e7, 1e7].
4949
### **Java**
5050

5151
```java
52+
class Solution {
53+
public String convertToBase7(int num) {
54+
if (num == 0) {
55+
return "0";
56+
}
57+
if (num < 0) {
58+
return "-" + convertToBase7(-num);
59+
}
60+
StringBuilder sb = new StringBuilder();
61+
while (num != 0) {
62+
sb.append(num % 7);
63+
num /= 7;
64+
}
65+
return sb.reverse().toString();
66+
}
67+
}
5268

5369
```
5470

0 commit comments

Comments
 (0)