Simple but maybe not the fastest JAVA solution


  • 0
    V

    public class Solution {

    public List<String> generatePossibleNextMoves(String s) {
        ArrayList<String> result = new ArrayList<String>();
        char[] c = s.toCharArray();
        if(c.length < 2) return result;
        for(int i = 1; i < c.length; i++) {
            if(c[i-1] == '+' && c[i] == '+') {
                c[i-1] = '-';
                c[i] = '-';
                result.add(new String(c));
                c[i-1] = '+';
                c[i] = '+';
            }
        }
        return result;
    }
    

    }


Log in to reply
 

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