-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverse_Vowels_of_a_String.java
More file actions
35 lines (33 loc) · 992 Bytes
/
Reverse_Vowels_of_a_String.java
File metadata and controls
35 lines (33 loc) · 992 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
package com.leet_code;
import java.sql.SQLOutput;
public class Reverse_Vowels_of_a_String {
public static void main(String[] args) {
System.out.println(reverseVowels("racecar"));
}
public static String reverseVowels(String s) {// two pointer approch
int n= s.length();
char ch[] =s.toCharArray();
int st=0;
int en=s.length()-1;
while (st<en){
if (!isvoval(ch[st])) {
st++;
} else if (!isvoval(ch[en])) {
en--;
}else {
char temp=ch[st];
ch[st]=ch[en];
ch[en]=temp;
st++;
en--;
}
}
return String.valueOf(ch);
}
public static boolean isvoval(char c){
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' ) {
return true;
}
return false;
}
}