-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_345.java
More file actions
24 lines (23 loc) · 791 Bytes
/
Copy pathproblem_345.java
File metadata and controls
24 lines (23 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
345. Reverse Vowels of a StringGiven 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. */
class Solution {
public String reverseVowels(String s) {
String vow = "", vow_condition = "aeiouAEIOU", copy="";
int x = 0;
for(int i = 0;i<s.length();i++){
if(vow_condition.indexOf(s.charAt(i)) > -1){
vow = s.charAt(i) + vow;
}
}
for(int i = 0;i<s.length();i++){
if(vow_condition.indexOf(s.charAt(i)) > -1){
copy += vow.charAt(x++);
}
else{
copy += s.charAt(i);
}
}
return copy;
}
}