Golang 9 ms


  • 0
    R
    import "strconv"
    
    func countAndSay(n int) string {
        s:="1"
        for i:=0; i < n-1; i++ {
            lt, temp, count := s[0], "", 0
            for j:=0; j < len(s); j++ {
                if lt == s[j] {
                    count += 1
                } else {
                    temp = fmt.Sprintf("%s%d%c", temp, count, lt)
                    lt = s[j]
                    count = 1
                }
            }
            temp = fmt.Sprintf("%s%d%c", temp, count, lt)
            s = temp
        }
        return s
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.