π
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.