(List<List<String>> result, List<String> list, int level, int n, boolean[] used)
| 18 | } |
| 19 | |
| 20 | public static void backtrace(List<List<String>> result, List<String> list, int level, int n, boolean[] used){ |
| 21 | if(level == n) result.add(new ArrayList<String>(list)); |
| 22 | else{ |
| 23 | for(int i = 0; i < n; i++){ |
| 24 | if(used[i]) continue; |
| 25 | if(isValid(list, level, i, n)){ |
| 26 | list.add(createQueen(n, i)); |
| 27 | used[i] = true; |
| 28 | backtrace(result, list, level + 1, n, used); |
| 29 | used[i] = false; |
| 30 | list.remove(list.size() - 1); |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | public static boolean isValid(List<String> list, int row, int column, int n){ |
| 36 | if(row > 0){ |
| 37 | String cmp = list.get(row - 1); |
no test coverage detected