📜

Capitalize String

Capitalize String
쉬움 문자열 +10pts

Problem

Write a function that capitalizes the first letter of a string.

Examples

Input: capitalize("hello")
Output: "Hello"

Explanation

이 문제는 **문자열 분리**와 **대소문자 변환**을 결합하여 첫 글자만 대문자로 만드는 방법을 학습합니다. **핵심 전략: 분리 후 결합** 1. 첫 글자: str[0] 2. 나머지: str.slice(1) 3. 결합: 대문자 첫 글자 + 나머지 **"hello" 처리 과정** - str[0] → "h" - "h".toUpperCase() → "H" - str.slice(1) → "ello" - "H" + "ello" → "Hello" **빈 문자열 처리** 빈 문자열에서 str[0]은 undefined입니다. 이 경우 에...

View detailed explanation →

Key Concepts

toUpperCase 메서드 slice 메서드 문자열 인덱싱 빈 문자열 처리
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.