A beat 95.83% of java solution


  • 0
    C
    public static String reverseString(String s) {
    
    		char c;
    		char[] cc = s.toCharArray();
    		int l = s.length(),left = 0, right = l - 1;
    		while (true) {
    			while (left < right
    					&& cc[left] != 'a' && cc[left] != 'e' && cc[left] != 'i' && cc[left] != 'o' && cc[left] != 'u' && cc[left] != 'A' && cc[left] != 'E' && cc[left] != 'I' && cc[left] != 'O' && cc[left] != 'U')
    				left++;
    			while (right > left
    					&& cc[right] != 'a' && cc[right] != 'e' && cc[right] != 'i' && cc[right] != 'o' && cc[right] != 'u' && cc[right] != 'A' && cc[right] != 'E' && cc[right] != 'I' && cc[right] != 'O' && cc[right] != 'U') {
    				right--;
    			}
    			if (left >= right) {
    				break;
    			} else {
    				c = cc[left];
    				cc[left] = cc[right];
    				cc[right] = c;
    				left++;
    				right--;
    			}
    		}
    		String s1 = String.valueOf(cc);
    		return s1;
    
    	}
    

Log in to reply
 

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