Java


  • 0
    J

    Use indexOf(a, from)

    public List<String> generatePossibleNextMoves(String s) {      
        Set<String> result = new HashSet();
        int from = 0;
        for (int i=0; i<s.length()-1; i++) {
            int index = s.indexOf("++", from);
            from = index+1;
            StringBuffer temp = new StringBuffer();
            if (index >= 0) {
                temp.append(s.substring(0, index));
                temp.append("--");
                temp.append(s.substring(index+2));
            }
            if (!temp.toString().equals("")) {
                result.add(temp.toString());
            }
        }
        return new ArrayList(result);
    }

Log in to reply
 

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