```
def count_and_say0(s)
return '1' if s == ''
front = nil; cnt = 0; res = ''
len = s.length
for i in (0...len)
if s[i] == front
cnt += 1
else
res << "#{cnt}#{s[i-1]}" if not front.nil?
cnt = 1
front = s[i]
end
end
res << "#{cnt}#{s[len-1]}"
end
# @param {Integer} n
# @return {String}
def count_and_say(n)
s = ''
1.upto(n) do
s = count_and_say0(s)
end
return s
end
```