Java simple solution beat 85%


  • 0
    K

    if(s == null || s.length() == 1) return s;
    char[] chars = s.toCharArray();
    int low = 0;
    int high = chars.length - 1;
    while(low < high){
    if(chars[low] == 'a' || chars[low] == 'e'||chars[low] == 'i'||chars[low] == 'o'||chars[low] == 'u'||
    chars[low] == 'A' || chars[low] == 'E'||chars[low] == 'I'||chars[low] == 'O'||chars[low] == 'U'){
    if(chars[high] == 'a' || chars[high] == 'e'||chars[high] == 'i'||chars[high] == 'o'||chars[high] == 'u'||
    chars[high] == 'A' || chars[high] == 'E'||chars[high] == 'I'||chars[high] == 'O'||chars[high] == 'U'){
    char temp = chars[high];
    chars[high] = chars[low];
    chars[low] = temp;
    low++;
    high--;
    continue;
    }
    else high--;
    }else low++;
    }
    return String.valueOf(chars);


Log in to reply
 

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