Using std::adjacent_find


  • 0
    J
        vector<string> generatePossibleNextMoves(string s) {
            vector<string> ret;
            
            const auto plus2 = [] (char a, char b) -> bool { return a == b && a == '+'; };
            auto p1 = adjacent_find(s.begin(), s.end(), plus2); 
            while(p1 != s.end()) {
                auto p2 = next(p1);
                *p1 = *p2 = '-';
                ret.push_back(s);
                *p1 = *p2 = '+';   
                p1 = adjacent_find(p2, s.end(), plus2); 
            }
            
            return ret;
        }
    

Log in to reply
 

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