Skip to content

Commit 51c2064

Browse files
author
Shuo
committed
U: string()
1 parent 32e298b commit 51c2064

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

problems/base-7/base_7.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package problem504
22

3+
import "fmt"
4+
35
func convertToBase7(num int) string {
46
ans := ""
57
if num < 0 {
@@ -8,5 +10,5 @@ func convertToBase7(num int) string {
810
if num >= 7 {
911
ans += convertToBase7(num / 7)
1012
}
11-
return ans + string('0'+num%7)
13+
return ans + fmt.Sprintf("%c", '0'+num%7)
1214
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package problem168
22

3+
import "fmt"
4+
35
// Solution 1: recursive
46
func convertToTitle(n int) string {
57
if n--; n < 26 {
6-
return string(n + 'A')
8+
return fmt.Sprintf("%c", n+'A')
79
}
8-
return convertToTitle(n/26) + string(n%26+'A')
10+
return convertToTitle(n/26) + fmt.Sprintf("%c", n%26+'A')
911
}
1012

1113
// Solution 2: iteration
1214
func convertToTitle2(n int) string {
1315
ans := ""
1416
for ; n > 0; n /= 26 {
1517
n--
16-
ans = string(n%26+'A') + ans
18+
ans = fmt.Sprintf("%c", n%26+'A') + ans
1719
}
1820
return ans
1921
}

problems/find-common-characters/find_common_characters.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package problem1002
22

3+
import "fmt"
4+
35
func commonChars(A []string) []string {
46
ans, m, l := make([]string, 0), make([][26]int, len(A)), len(A)
57
for i, str := range A {
@@ -19,7 +21,7 @@ func commonChars(A []string) []string {
1921
}
2022
}
2123
if c >= 0 {
22-
ans = append(ans, string(i+'a'))
24+
ans = append(ans, fmt.Sprintf("%c", i+'a'))
2325
}
2426
}
2527
}

0 commit comments

Comments
 (0)