[LeetCode] 557. Reverse Words in a String III

Chobby·2025년 4월 14일
1

LeetCode

목록 보기
351/427

😎풀이

  1. splitted: 공백을 기준으로 단어 분리
  2. reversed: 단어를 역순으로 변환
  3. 변환된 reversed를 공백을 기준으로 연결하여 반환
function reverseWords(s: string): string {
    const splitted = s.split(' ')
    const reversed = splitted.map(word => word.split('').reverse().join(''))
    return reversed.join(' ')
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글