Array / String· 15 min

Reverse Vowels of a String

LeetCode #345 · Easy · Interactive step-by-step visualization

Setup

Example inputs = "LeetCode"
Step 1 / 14

Current step

1 / 14

Place pointers at both ends. Only vowels will change position.

Step log

Consonants stay fixed; vowel items keep stable IDs while moving.
LeetCode
Active
Comparing
Committed
Rejected or blocked
reverse-vowels-of-a-string.java
1public String reverseVowels(String value) {
2 char[] chars = value.toCharArray();
3 int left = 0, right = chars.length - 1;
4 while (left < right) {
5 while (left < right && !isVowel(chars[left])) left++;
6 while (left < right && !isVowel(chars[right])) right--;
7 char temp = chars[left]; chars[left] = chars[right]; chars[right] = temp;
8 left++; right--;
9 }
10 return new String(chars);
11}
● Java
Time
O(n)
Space
O(n)
Pattern
two pointers
Frames
14