Skip to content

Commit

Permalink
add: solve #238 Encode and Decode strings with ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Yjason-K committed Jan 9, 2025
1 parent 2236c56 commit 6bed3de
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions encode-and-decode-strings/Yjason-K.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @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(':');
}

0 comments on commit 6bed3de

Please sign in to comment.