原题链接在这里:https://leetcode.com/problems/flip-game/
若是连着的"++", 就把这段用"--"替代放到res中.
Time Complexity: O(n). Space: O(1) regardless res.
AC Java:
1 public class Solution { 2 public List<String> generatePossibleNextMoves(String s) { 3 List<String> res = new ArrayList<String>(); 4 for(int i = 1; i<s.length(); i++){ 5 if(s.charAt(i-1) == ‘+‘ && s.charAt(i) == ‘+‘){ 6 res.add(s.substring(0,i-1) + "--" + s.substring(i+1)); 7 } 8 } 9 return res; 10 } 11 }
原文:http://www.cnblogs.com/Dylan-Java-NYC/p/5186278.html