Simple solution to a simple problem


  • 0
    T
    public class Solution {
        public List<String> generatePossibleNextMoves(String s) {
            List<String> list = new ArrayList<>();
            if(s.length()==0 || s.equals("--")) return list;
            helper(list, s, 0);
            return list;
        }
        
        public void helper(List<String> list, String s, int start){
            if(start>=s.length()-1) return;
            
            if(s.charAt(start)==s.charAt(start+1)){
                
                if(s.charAt(start)=='+'){
                     String str="";
                     str = "--";
                     String temp = s.substring(0,start)+str;
                    if(start+2 < s.length()){
                        temp+=s.substring(start+2,s.length());
                    }
                    list.add(temp);
                }
                
                
            }
            helper(list, s, start+1);
        }
    }

Log in to reply
 

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