Array / String· 15 min
Reverse Vowels of a String
LeetCode #345 · Easy · Interactive step-by-step visualization
Setup
Example input
s = "LeetCode"Step 1 / 14
Current step
1 / 14Place pointers at both ends. Only vowels will change position.
Step log
Consonants stay fixed; vowel items keep stable IDs while moving.
Characters
L
R
L
0e
1e
2t
3C
4o
5d
6e
7LeetCode
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
