Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 465x 30x 435x 435x 435x 435x 40113x 40113x 40113x 40113x 40113x 40113x 435x | export default function countAndSay(n: number): string {
if (n === 1)
return '1'
const prevSay = countAndSay(n - 1)
let curSay = ''
let pos = 0
while (pos < prevSay.length) {
const start = pos
let end = pos + 1
while (prevSay[start] === prevSay[end]) end++
const times = end - start
curSay += `${times}${prevSay[start]}`
pos += end - start
}
return curSay
}
|