๐Ÿ“œ

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.