class Solution {
public int[][] solution(int n) {
List<Integer[]> answer_list = new ArrayList<>();
hanoi(answer_list, n, 1,3,2);
int[][] answer = new int[answer_list.size()][2];
for(int i=0; i<answer.length; i++) {
Integer[] now = answer_list.get(i);
answer[i][0] = now[0];
answer[i][1] = now[1];
}
return answer;
}
void hanoi(List<Integer[]> answer_list, int n, int start, int to, int via){
if(n==1) {
move(answer_list, 1, start, to);
} else {
hanoi(answer_list, n–1, start, via, to);
move(answer_list, n, start, to);
hanoi(answer_list, n–1, via, to, start);
}
}
void move(List<Integer[]> answer_list, int n, int start, int to) {
Integer[] answer = {start, to};
answer_list.add(answer);
}
}
Join our affiliate family and watch your profits soar—sign up today! https://shorturl.fm/A6MFq
Earn big by sharing our offers—become an affiliate today! https://shorturl.fm/UfyZV
Become our affiliate and watch your wallet grow—apply now! https://shorturl.fm/Gd88j
Apply now and receive dedicated support for affiliates! https://shorturl.fm/Z9xp8
Share your unique link and cash in—join now! https://shorturl.fm/ziYb4
Start earning passive income—join our affiliate network today! https://shorturl.fm/4Tvcg
Promote our brand and watch your income grow—join today! https://shorturl.fm/neJld
Become our affiliate and watch your wallet grow—apply now! https://shorturl.fm/hkocb
Join our affiliate community and maximize your profits! https://shorturl.fm/jhxIx
Earn recurring commissions with each referral—enroll today! https://shorturl.fm/TjuHP