forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYjason-K.ts
More file actions
28 lines (26 loc) ยท 820 Bytes
/
Yjason-K.ts
File metadata and controls
28 lines (26 loc) ยท 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* @description ๋ฌธ์์ด ๋ฐฐ์ด์ ํ๋์ ๋ฌธ์์ด๋ก ์ธ์ฝ๋ฉํฉ๋๋ค.
* @param {string[]} strs - ๋ฌธ์์ด ๋ฐฐ์ด
* @returns {string} ์ธ์ฝ๋ฉ๋ ๋ฌธ์์ด
*
* ์๊ฐ ๋ณต์ก๋: O(N)
* - N์ ์
๋ ฅ ๋ฐฐ์ด์ ๋ชจ๋ ๋ฌธ์์ด ๊ธธ์ด์ ํฉ
* ๊ณต๊ฐ ๋ณต์ก๋: O(1)
* - ์ถ๊ฐ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ ์์
*/
function encode(strs: string[]): string {
return strs.join(':');
}
/**
* @description ์ธ์ฝ๋ฉ๋ ๋ฌธ์์ด์ ๋ค์ ๋ฌธ์์ด ๋ฐฐ์ด๋ก ๋์ฝ๋ฉํฉ๋๋ค.
* @param {string} s - ์ธ์ฝ๋ฉ๋ ๋ฌธ์์ด
* @returns {string[]} ๋์ฝ๋ฉ๋ ๋ฌธ์์ด ๋ฐฐ์ด
*
* ์๊ฐ ๋ณต์ก๋: O(N)
* - N์ ์
๋ ฅ ๋ฌธ์์ด์ ๊ธธ์ด
* ๊ณต๊ฐ ๋ณต์ก๋: O(1)
* - ์ถ๊ฐ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ ์์
*/
function decode(s: string): string[] {
return s.split(':');
}