public class Solution { 
	public ArrayList<String[]> rockPaperScissors(int rounds) {
    ArrayList<String[]> outcomes = new ArrayList<>();
    return permutation(rounds, new String[]{}, outcomes);
  }
  public ArrayList<String[]> permutation(int roundsToGo, String[] playedSoFar, ArrayList<String[]> outcomes) {
    if(roundsToGo == 0) {   // 탈출문
      outcomes.add(playedSoFar);   
      return outcomes;
    }
    String[] rps = new String[]{"rock", "paper", "scissors"};
    for(int i = 0; i < rps.length; i++) { // 재귀 탈줄문 작동시 i++, 다시 재귀 시작
      String currentPlay = rps[i];
      String[] concatArray = Arrays.copyOf(playedSoFar, playedSoFar.length + 1);  
      concatArray[concatArray.length - 1] = currentPlay;
      outcomes = permutation(roundsToGo - 1, concatArray, outcomes); //재귀 
    }
    return outcomes;
  }
}
댓글남기기