Approach

We just simply check the last char to see if it is 0,2,4,6,8. We remove the character if it is not one of them, the final string then would be the answer.

Code

class Solution {
public:
    string largestEven(string s) {
        while(s.size() > 0) {
            if((s[s.size()-1] - '0') % 2 == 0) break;
            s.pop_back();
        }
        return s;
    }
};