Remove vowels from string | Practice | GeeksforGeeks

Given a string, remove the vowels from the string.
Example 1:
Input: S = "welcome to geeksforgeeks"
Output: wlcm t gksfrgks
Explanation: Ignore vowels and print other
characters 
Example 2:
Input: S = "what is your name ?"
Output: wht s yr nm ?
Explanation: Ignore vowels and print other
characters 
Your task:
Your task is to complete the function removeVowels() which takes a single string as input and returns the modified string. You need not take any input or print anything.
Expected Time Complexity: O(|s|)
Expected Auxiliary Space: O(1)
Constraints:
1 <= |S| <= 105
Alphabets are lower cases only
0
visionsameer394 days ago
IN PYTHON 
SIMPLE SOLUTION
class Solution:def removeVowels(self, S):   s1='aioueAIOUE'   l1=[]   for i in S:       if i not in s1:           l1.append(i)   return "".join(l1)            
0
aravindmn75831 week ago
simple solution in c++_____
using regex____
string removeVowels(string S){
	regex r("[aeiouAEIOU]");
	return regex_replace(S,r,"");
	}
	
0
guptalittle222 weeks ago
JAVA
class Solution {
   String removeVowels(String S) {
       // code here
       S = S.replaceAll("a","");
       S = S.replaceAll("e","");
       S = S.replaceAll("i","");
       S = S.replaceAll("o","");
       S = S.replaceAll("u","");
      return S; 
   }
}
0
guptalittle222 weeks ago
S = S.replaceAll("o","");
0
sayanmazumder9993 weeks ago
JAVA
     String V = "aeiouAEIOU";     String c;     for(int i = 0; i<V.length(); i++) {     c = String.valueOf(V.charAt(i));     S = S.replaceAll(c, ""); }     return S; 
0
neelasatyasai931 month ago
#python
class Solution:def removeVowels(self, S):    n1=S.replace("a","")    n2=n1.replace("e","")    n3=n2.replace("i","")    n4=n3.replace("o","")    n5=n4.replace("u","")     return n5
             (OR)
 def removeVowels(self, S):    S=S.replace("a","")    S=S.replace("e","")    S=S.replace("i","")    S=S.replace("o","")    S=S.replace("u","")          return S
0
khabir21ug1 month ago
CPP Solution
string removeVowels(string S) 
	{
	    // Your code goes here
	    string temp;
	    for(int m=0; m<S.size(); m++){
	        if( S[m]=='a' || S[m]=='e' || S[m]=='i' || S[m]=='o' || S[m]=='u'){
	            continue;
	        }
	        else{
	            temp.push_back(S[m]);
	        }
	    }
	    return temp;
	}
+2
princejee20192 months ago
C++ CODE (USING STL) || EASY TO UNDERSTAND
class Solution{public:  string removeVowels(string S) {    // Your code goes here    S.erase(remove(S.begin(),S.end(),'a'),S.end());     S.erase(remove(S.begin(),S.end(),'e'),S.end());      S.erase(remove(S.begin(),S.end(),'i'),S.end());       S.erase(remove(S.begin(),S.end(),'o'),S.end());        S.erase(remove(S.begin(),S.end(),'u'),S.end());       return S;}};
+1
prashantsagar0732 months ago
Python 
class Solution:
	def removeVowels(self, S):
		# code here
		t=""
        for c in S:
            for i in "ieaouIEAOU":
                if c==i:
                    c=""
                else:
                    c=c
            t=t+c
        return t
0
mris127893 months ago
IN C++ LANGUAGE:
string removeVowels(string S) {    // Your code goes here    string new1="";    for(int i=0;S[i]!='\0';i++){        if(S[i]=='a'||S[i]=='e'||S[i]=='i'||S[i]=='o'||S[i]=='u'){            continue;        }        else{            new1+=S[i];        }    }    return new1;}
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.