diff --git a/eunjoo/0038-count-and-say/0038-count-and-say.ts b/eunjoo/0038-count-and-say/0038-count-and-say.ts new file mode 100644 index 0000000..2a6e36b --- /dev/null +++ b/eunjoo/0038-count-and-say/0038-count-and-say.ts @@ -0,0 +1,20 @@ +function countAndSay(n: number): string { + let ans = '1'; + + for(let i = 1; i < n; i++) { + let curr = ''; + let cnt = 1; + + for(let j = 0; j < ans.length; j++) { + if(ans[j] === ans[j+1]) { + cnt++; + } else { + curr += cnt + ans[j]; + cnt = 1; + } + } + ans = curr; + } + + return ans; +}; diff --git a/eunjoo/0038-count-and-say/README.md b/eunjoo/0038-count-and-say/README.md new file mode 100644 index 0000000..22d8668 --- /dev/null +++ b/eunjoo/0038-count-and-say/README.md @@ -0,0 +1,39 @@ +

38. Count and Say

Medium


The count-and-say sequence is a sequence of digit strings defined by the recursive formula:

+ + + +

To determine how you "say" a digit string, split it into the minimal number of substrings such that each substring contains exactly one unique digit. Then for each substring, say the number of digits, then say the digit. Finally, concatenate every said digit.

+ +

For example, the saying and conversion for digit string "3322251":

+ +

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

+ +

 

+

Example 1:

+ +
Input: n = 1
+Output: "1"
+Explanation: This is the base case.
+
+ +

Example 2:

+ +
Input: n = 4
+Output: "1211"
+Explanation:
+countAndSay(1) = "1"
+countAndSay(2) = say "1" = one 1 = "11"
+countAndSay(3) = say "11" = two 1's = "21"
+countAndSay(4) = say "21" = one 2 + one 1 = "12" + "11" = "1211"
+
+ +

 

+

Constraints:

+ + +
\ No newline at end of file