View on GitHub

leetcode-diaries

A journal to record the solution of the various Leetcode problems solved over the course of time.

Reverse Vowels of a String

Leetcode problem 345; Difficulty: Easy

Problem Statement

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

Constraints:

Example 1:

Input: s = "hello"

Output: "holle"

Example 2:

Input: s = "leetcode"

Output: "leotcede"

Submitted Solution

The first solution received the following rating on Leetcode:

image

By making a simple and small improvement to the implementation of the IsVowel convenience method in the second solution, the Leetcode rating improved to:

image