-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathReverseVowel1.java
More file actions
46 lines (39 loc) · 921 Bytes
/
ReverseVowel1.java
File metadata and controls
46 lines (39 loc) · 921 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class ReverseVowel1 {
public String reverseVowels(String s) {
boolean[] map = new boolean[256];
map['a'] = true;
map['e'] = true;
map['i'] = true;
map['u'] = true;
map['o'] = true;
map['A'] = true;
map['E'] = true;
map['I'] = true;
map['U'] = true;
map['O'] = true;
char[] sCharArray = s.toCharArray();
int begin = 0;
int end = s.length() - 1;
while (begin < end) {
while (begin < end && map[sCharArray[begin]] == false)
++begin;
while (begin < end && map[sCharArray[end]] == false)
--end;
if (begin < end) {
char temp = sCharArray[begin];
sCharArray[begin] = sCharArray[end];
sCharArray[end] = temp;
}
--end;
++begin;
}
return new String(sCharArray);
}
}
/*Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Input: "hello"
Output: "holle"
Note:
The vowels does not include the letter "y".
*/