Skip to content

Commit 5d8872f

Browse files
committed
update: 38
1 parent 8094a7e commit 5d8872f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
3333
| 33 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/) | [JavaScript](./src/search-in-rotated-sorted-array/res.js) | Medium |
3434
| 34 | [Search for a Range](https://leetcode.com/problems/search-for-a-range/) | [JavaScript](./src/search-for-a-range/res.js) | Medium |
3535
| 35 | [Search Insert Position](https://leetcode.com/problems/search-insert-position/) | [JavaScript](./src/search-insert-position/res.js) | Easy |
36+
| 38 | [count-and-say](https://leetcode.com/problems/count-and-say/) | [TypeScript](./src/count-and-say/res.ts) | Medium |
3637
| 39 | [Combination Sum](https://leetcode.com/problems/combination-sum/) | [JavaScript](./src/combination-sum/res.js) | Medium |
3738
| 40 | [Combination Sum II](https://leetcode.com/problems/combination-sum-ii/) | [JavaScript](./src/combination-sum-ii/res.js) | Medium |
3839
| 41 | [First Missing Positive](https://leetcode.com/problems/first-missing-positive/description/) | [JavaScript](./src/first-missing-positive/res.js) | Hard |

src/count-and-say/res.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function countAndSay(n: number): string {
2+
let result = '1';
3+
4+
for (let i = 1; i < n; i++) {
5+
let newResult: string = '';
6+
let stackList: string[] = result.split('');
7+
8+
let currentCount = 1;
9+
let currentChar = stackList[0];
10+
for (let j = 1; j < stackList.length; j++) {
11+
if (currentChar === stackList[j]) {
12+
currentCount++;
13+
} else {
14+
newResult += `${currentCount}${currentChar}`;
15+
currentChar = stackList[j];
16+
currentCount = 1;
17+
}
18+
}
19+
20+
if (currentCount) {
21+
newResult += `${currentCount}${currentChar}`;
22+
}
23+
24+
result = newResult;
25+
}
26+
27+
return result;
28+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy