123. Count and Say

Medium · String

The count-and-say sequence is a sequence of digit strings defined by counting the digits of the previous term. Starting with "1", each subsequent term describes the previous term by counting consecutive identical digits and stating the count followed by the digit itself.

Given an integer n, return the nth term of the count-and-say sequence.

Examples

Example 1
Input: n = 1
Output: "1"
Explanation: The first term is "1" by definition.
Example 2
Input: n = 4
Output: "1211"
Explanation: Term 1: "1"
Term 2: "11" (one 1)
Term 3: "21" (two 1s)
Term 4: "1211" (one 2, then one 1)

Constraints