프라이D
프라이Develog(❁´◡`❁)
프라이D
전체 방문자
오늘
어제
  • ALL (378)
    • TDD, Cleancode with JavaScr.. (5)
    • 프로젝트 (32)
      • work (3)
      • 직접 만드는 기술 블로그 (2)
      • 데일리 옥션 (19)
      • 모락모락 (8)
    • Computer Science (1)
    • Algorithm & 자료구조 (94)
      • 알고리즘 w.JavaScript (53)
      • 자료구조 (5)
      • (인프런) 자바스크립트 알고리즘 문제풀이 (34)
    • JavaScript (45)
      • JavaScript (41)
      • 모던 자바스크립트 Deep Dive (4)
    • WEB (13)
    • 회고 (12)
    • TIL (109)
    • WIL (7)
    • Stacks (20)
      • React.js (6)
      • Next.js (1)
      • Redux (3)
      • Node.js (2)
      • GIT (2)
      • SAP (1)
    • 15일 메이킹 프로젝트 (15)
    • 이전 기록 (14)
    • ETC. (5)
    • ---------------2021 (6)
      • 내일배움단-웹개발 5주 (2)
      • 정보처리기사 (4)

블로그 메뉴

  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록

공지사항

인기 글

태그

  • nomadcoder
  • vanilaJS
  • 내일배움카드
  • JavaScript
  • 국비지원
  • 자바스크립트알고리즘
  • 자바스크립트비트마스크
  • 비트마스크
  • 알고리즘
  • 코드스테이츠
  • 투포인터알고리즘
  • MySQL
  • 내일배움단
  • Til
  • nomadcoders
  • 코딩프로젝트
  • 모던자바스크립트딥다이브
  • 스파르타코딩클럽
  • 자바스크립트
  • 2023 인프콘 후기

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
프라이D

프라이Develog(❁´◡`❁)

Algorithm & 자료구조/알고리즘 w.JavaScript

[Leetcode] 345. Reverse Vowels of a String

2024. 1. 3. 22:30
 

Reverse Vowels of a String - LeetCode

Can you solve this real interview question? Reverse Vowels of a String - Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than onc

leetcode.com

Given a string s, reverse only all the vowels in the string and return it.
The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once.

 

풀이

/*
[문제]
- 문자열 s가 주어진다.
- 문자열 s의 모든 모음을 반대로 뒤집어서 리턴
- 모음은 대/소문자로 주어짐
 */
const VOWELS_SET = new Set(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']);
var reverseVowels = function (s) {
  const vowels = [];

  const replacedS = [...s].map((letter) => {
    if (VOWELS_SET.has(letter)) {
      vowels.push(letter);
      return '*';
    }

    return letter;
  });

  const reversed = replacedS.map((letter) => {
    if (letter === '*') return vowels.pop();
    return letter;
  });

  return reversed.join('');
};
저작자표시 (새창열림)

'Algorithm & 자료구조 > 알고리즘 w.JavaScript' 카테고리의 다른 글

151. Reverse Words in a String  (0) 2024.01.03
[Leetcode] 605. Can Place Flowers  (0) 2023.12.31
[Leetcode] 1431. Kids With the Greatest Number of Candies  (0) 2023.12.31
[Leetcode] 1071. Greatest Common Divisor of Strings  (0) 2023.12.28
[Leetcode] 1768.Merge Strings Alternately  (2) 2023.12.18
    'Algorithm & 자료구조/알고리즘 w.JavaScript' 카테고리의 다른 글
    • 151. Reverse Words in a String
    • [Leetcode] 605. Can Place Flowers
    • [Leetcode] 1431. Kids With the Greatest Number of Candies
    • [Leetcode] 1071. Greatest Common Divisor of Strings
    프라이D
    프라이D
    틀린내용 정정 및 개선사항은 언제든지 댓글 달아주세요 :D

    티스토리툴바