Java solution with O(n)


  • 0
    S
    public class Solution {
        public List<String> generatePossibleNextMoves(String s) {
            List<String> result = new ArrayList<String>();
            for(int i=0; i<s.length()-1; i++) {
                if(s.charAt(i) == '+' && s.charAt(i+1) =='+') {
                    result.add("" + s.substring(0,i) + "--" + s.substring(i+2, s.length()));
                }
            }
            return result;
        }
    }
    

Log in to reply
 

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