๐
Replace All
Replace All์ฌ์ ๋ฌธ์์ด +10pts
Problem
Write a function that replaces all occurrences of a substring.
Examples
Input:
replaceAll("hello world", "o", "0")Output:
"hell0 w0rld"Explanation
์ด ๋ฌธ์ ๋ **split()๊ณผ join()**์ ์กฐํฉํ์ฌ ๋ฌธ์์ด์ ๋ชจ๋ ์ผ์น ํญ๋ชฉ์ ๋ฐ๊พธ๋ ๋ฐฉ๋ฒ์ ํ์ตํฉ๋๋ค. ## ํต์ฌ ๊ฐ๋ : ๋ชจ๋ ๋ฐ๊พธ๊ธฐ ํจํด ๋ชจ๋ ์ผ์น ํญ๋ชฉ์ ๋ฐ๊พธ๋ ๋ฐฉ๋ฒ์ ์ฌ๋ฌ ๊ฐ์ง๊ฐ ์์ต๋๋ค. ### ๋ฐฉ๋ฒ 1: split + join (๊ถ์ฅ) ```javascript str.split(search).join(replace) ``` - split์ผ๋ก ๋ฌธ์์ด์ ๋ฐฐ์ด๋ก ๋ถ๋ฆฌ - join์ผ๋ก ๋ค๋ฅธ ๋ฌธ์๋ก ์ฐ๊ฒฐ ### ๋ฐฉ๋ฒ 2: replaceAll (ES2021+) ```javascript str.replaceAll(sear...
View detailed explanation โKey Concepts
split ๋ฉ์๋ join ๋ฉ์๋ replaceAll ๋ฌธ์์ด ์นํ
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.