MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / backtrace

Method backtrace

Java/LeetCodeN-Queens.java:20–34  ·  view source on GitHub ↗
(List<List<String>> result, List<String> list, int level, int n, boolean[] used)

Source from the content-addressed store, hash-verified

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);

Callers 1

solveNQueensMethod · 0.95

Calls 5

isValidMethod · 0.95
createQueenMethod · 0.95
addMethod · 0.45
removeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected