a simple c++ code without STL


  • 0
    A
    bool isVowels(char c) {
    if (c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' 
        || c == 'o' || c == 'O' || c == 'u' || c == 'U') return true;
    else return false;
    }
    
     class Solution {
     public:
     string reverseVowels(string s) {
        int front = 0, rear = s.size()-1;
        for (int i = front; i < rear; i++) {
            if (isVowels(s[i])) {
                front = i;
                for (int j = rear; j > front; j--) {
                    if (isVowels(s[j])) {
                        rear = j;
                        swap(s[front], s[rear]);
                        break;
                    }
                }
                rear--;
            }
        }
        return s;
    }
    };
    

    it maybe a simple code, I think.


Log in to reply
 

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