293. Flip Game

T: O(n)

S: O(n)

class Solution {
    public List<String> generatePossibleNextMoves(String currentState) {
        List<String> res = new ArrayList<>();
        char[] str = currentState.toCharArray();
        for (int i = 0; i < str.length-1;i++) {
            if (str[i] == '+' && str[i+1] == '+') {
                char[] newStr = new String(currentState).toCharArray();
                newStr[i] = '-';
                newStr[i+1] = '-';
                res.add(String.valueOf(newStr));
            }
        }
        return res;
    }
}

Last updated