Skip to content

Commit 6bed3de

Browse files
committed
add: solve #238 Encode and Decode strings with ts
1 parent 2236c56 commit 6bed3de

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @description ๋ฌธ์ž์—ด ๋ฐฐ์—ด์„ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ์ธ์ฝ”๋”ฉํ•ฉ๋‹ˆ๋‹ค.
3+
* @param {string[]} strs - ๋ฌธ์ž์—ด ๋ฐฐ์—ด
4+
* @returns {string} ์ธ์ฝ”๋”ฉ๋œ ๋ฌธ์ž์—ด
5+
*
6+
* ์‹œ๊ฐ„ ๋ณต์žก๋„: O(N)
7+
* - N์€ ์ž…๋ ฅ ๋ฐฐ์—ด์˜ ๋ชจ๋“  ๋ฌธ์ž์—ด ๊ธธ์ด์˜ ํ•ฉ
8+
* ๊ณต๊ฐ„ ๋ณต์žก๋„: O(1)
9+
* - ์ถ”๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ ์—†์Œ
10+
*/
11+
function encode(strs: string[]): string {
12+
return strs.join(':');
13+
}
14+
15+
/**
16+
* @description ์ธ์ฝ”๋”ฉ๋œ ๋ฌธ์ž์—ด์„ ๋‹ค์‹œ ๋ฌธ์ž์—ด ๋ฐฐ์—ด๋กœ ๋””์ฝ”๋”ฉํ•ฉ๋‹ˆ๋‹ค.
17+
* @param {string} s - ์ธ์ฝ”๋”ฉ๋œ ๋ฌธ์ž์—ด
18+
* @returns {string[]} ๋””์ฝ”๋”ฉ๋œ ๋ฌธ์ž์—ด ๋ฐฐ์—ด
19+
*
20+
* ์‹œ๊ฐ„ ๋ณต์žก๋„: O(N)
21+
* - N์€ ์ž…๋ ฅ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด
22+
* ๊ณต๊ฐ„ ๋ณต์žก๋„: O(1)
23+
* - ์ถ”๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ ์—†์Œ
24+
*/
25+
function decode(s: string): string[] {
26+
return s.split(':');
27+
}
28+

0 commit comments

Comments
ย (0)