Share my solution in C++ using string member function


  • 0
    Z
    class Solution {
    public:
        vector<string> generatePossibleNextMoves(string s) {
            vector<string> res;
            int i=s.find("++");
            while(i!=-1){
                string st=s;
                st.replace(i,2,"--");
                res.push_back(st);
                i=s.find("++",i+1);
            }
            
            return res;
        }
    };

Log in to reply
 

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