πŸ“œ

Reverse String

Reverse String
쉬움 λ¬Έμžμ—΄ +10pts

Problem

Write a function that reverses a string.

Examples

Input: reverseString("hello")
Output: "olleh"
Input: reverseString("JavaScript")
Output: "tpircSavaJ"

Explanation

이 λ¬Έμ œλŠ” **λ©”μ„œλ“œ 체이닝**을 톡해 λ¬Έμžμ—΄μ„ λ’€μ§‘λŠ” 방법을 ν•™μŠ΅ν•©λ‹ˆλ‹€. μ„Έ κ°€μ§€ λ°°μ—΄/λ¬Έμžμ—΄ λ©”μ„œλ“œλ₯Ό μ—°κ²°ν•˜μ—¬ μ‚¬μš©ν•©λ‹ˆλ‹€. **split('') - λ¬Έμžμ—΄μ„ λ°°μ—΄λ‘œ** 빈 λ¬Έμžμ—΄μ„ κ΅¬λΆ„μžλ‘œ μ‚¬μš©ν•˜λ©΄ λ¬Έμžμ—΄μ˜ 각 λ¬Έμžκ°€ λ°°μ—΄μ˜ μš”μ†Œκ°€ λ©λ‹ˆλ‹€: `"hello".split('')` β†’ `['h', 'e', 'l', 'l', 'o']` **reverse() - λ°°μ—΄ λ’€μ§‘κΈ°** λ°°μ—΄μ˜ μˆœμ„œλ₯Ό λ’€μ§‘μŠ΅λ‹ˆλ‹€ (원본 배열을 μˆ˜μ •): `['h', 'e', 'l', 'l', 'o'].reverse()` β†’ `['o', 'l', 'l', 'e',...

View detailed explanation β†’

Key Concepts

split λ©”μ„œλ“œ reverse λ©”μ„œλ“œ join λ©”μ„œλ“œ λ©”μ„œλ“œ 체이닝
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.