diff --git a/problem1.java b/problem1.java new file mode 100644 index 00000000..ae134a2e --- /dev/null +++ b/problem1.java @@ -0,0 +1,50 @@ +class Solution { + List> result; + int n; + public List> solveNQueens(int n) { + char[][] board = new char[n][n]; + for (int i=0; i(); + this.n = n; + + backtrack(board, new HashSet<>(), new HashSet<>(), new HashSet<>(), 0); + + return result; + } + + private void backtrack(char[][] board, Set colSet, Set negativeDiagSet, Set positiveDiagSet, int row) { + + if (row == n) { + List list = new ArrayList<>(); + for (int k=0; k=0 && newJ>=0 && newI