Clean java solution


  • 0
    W
    public List<String> generatePossibleNextMoves(String s) {
        int index = 0;
        List<String> res = new ArrayList<>();
        while (s.indexOf("++", index) != -1) {
            int i = s.indexOf("++", index);
            res.add(s.substring(0, i) + "--" + s.substring(i + 2));
            index = i + 1;
        }
        return res;
    }

Log in to reply
 

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