(n int)
| 3 | import "fmt" |
| 4 | |
| 5 | func 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 | } |
no outgoing calls