why my java takes 129ms


  • 0
    B

    Hi all, I am new java player
    For this problem I also use two pointer thought but I got 129 ms result which frustrated me. Could you look through my code and give some advice?

        public String reverseVowels(String s) {
            char[] t = s.toCharArray();
            int len = t.length;
            if(len <= 1)
            	return s;
            for(int i=0, j=len-1; i<=j;){
            	if(Pattern.matches("[aeiouAEIOU]", String.valueOf(t[i]))
            		&& Pattern.matches("[aeiouAEIOU]", String.valueOf(t[j])))
            	{
            		char tmp = t[i];
            		t[i]=t[j];
            		t[j]=tmp;
            		i++;
            		j--;
            	}
            	else if(Pattern.matches("[aeiouAEIOU]", String.valueOf(t[i])))
            		j--;
            	else if(Pattern.matches("[aeiouAEIOU]", String.valueOf(t[j])))
            		i++;
            	else{
            		i++; j--;
            	}
            		
            }
            String result = new String();
            result=String.valueOf(t);
            return result;
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.