LeetCode
leetcode.com › problems › reverse-vowels-of-a-string
Reverse Vowels of a String - LeetCode
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 once.
Videos
AlgoMonster
algo.monster › liteproblems › 345
345. Reverse Vowels of a String - In-Depth Explanation
In-depth solution and explanation for LeetCode 345. Reverse Vowels of a String in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.
GitHub
github.com › doocs › leetcode › blob › main › solution › 0300-0399 › 0345.Reverse Vowels of a String › README_EN.md
leetcode/solution/0300-0399/0345.Reverse Vowels of a String/README_EN.md at main · doocs/leetcode
class Solution: def reverseVowels(self, s: str) -> str: vowels = "aeiouAEIOU" i, j = 0, len(s) - 1 cs = list(s) while i < j: while i < j and cs[i] not in vowels: i += 1 while i < j and cs[j] not in vowels: j -= 1 if i < j: cs[i], cs[j] = cs[j], cs[i] i, j = i + 1, j - 1 return "".join(cs) class Solution { public String reverseVowels(String s) { boolean[] vowels = new boolean[128]; for (char c : "aeiouAEIOU".toCharArray()) { vowels[c] = true; } char[] cs = s.toCharArray(); int i = 0, j = cs.length - 1; while (i < j) { while (i < j && !vowels[cs[i]]) { ++i; } while (i < j && !vowels[cs[j]]) { --j; } if (i < j) { char t = cs[i]; cs[i] = cs[j]; cs[j] = t; ++i; --j; } } return String.valueOf(cs); } }
Author doocs
WalkCCC
walkccc.me › LeetCode › problems › 345
345. Reverse Vowels of a String - LeetCode Solutions
LeetCode Solutions in C++23, Java, Python, MySQL, and TypeScript.
YouTube
youtube.com › kevin naughton jr.
Reverse Vowels of a String - YouTube
For business inquiries email partnerships@k2.codes Discord: bit.ly/K2-discord
Published September 30, 2019 Views 26K
LeetCode-in-Java
leetcode-in-java.github.io › src › main › java › g0301_0400 › s0345_reverse_vowels_of_a_string
LeetCode-in-Java | Java-based LeetCode algorithm problem solutions, regularly updated.
The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both cases. ... public class Solution { private boolean isVowel(char c) { return c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U'; } public String reverseVowels(String str) { int i = 0; int j = str.length() - 1; char[] str1 = str.toCharArray(); while (i < j) { if (!isVowel(str1[i])) { i++; } else if (!isVowel(str1[j])) { j--; } else { // swapping char t = str1[i]; str1[i] = str1[j]; str1[j] = t; i++; j--; } } return String.copyValueOf(str1); } }
LeetCode
leetcode.com › problems › reverse-vowels-of-a-string › solutions › 2484211 › reverse-vowels-of-a-string
Official Solution - Reverse Vowels of a String - LeetCode
View official solution of Reverse Vowels of a String on LeetCode, the world's largest programming community.