MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / countAndSay

Function countAndSay

count_and_say_38/solution.go:5–26  ·  view source on GitHub ↗
(n int)

Source from the content-addressed store, hash-verified

3import "fmt"
4
5func countAndSay(n int) string {
6 if n == 1 {
7 return "1"
8 }
9
10 s := countAndSay(n - 1)
11 sNext := ""
12 ch := string(s[0])
13 freq := 0
14 for _, c := range s {
15 if string(c) == ch {
16 freq++
17 } else {
18 sNext += fmt.Sprintf("%d%s", freq, ch)
19 freq = 1
20 ch = string(c)
21 }
22 }
23
24 sNext += fmt.Sprintf("%d%s", freq, ch)
25 return sNext
26}

Callers 1

Test_countAndSayFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_countAndSayFunction · 0.68