<s>[INST] class Solution {
public:
    int maximum69Number (int num) {
        string s = to_string(num);
        int ct = 0;
        string result = "";
        for(int i = 0; i < s.length(); i++){
            if(s[i] != '9') {
                if(s[i] == '6') {
                    result += '9';
                } else {
                    result += s[i];
                }
            } else {
                if(ct == 0) {
                    result += '9';
                    ct = 1;
                } else {
                    result += s[i];
                }
            }
        }
        return stoi(result);
    }
};

This doesn't seem to run very efficiently. How can I make it more efficient?[/INST]