Skip to content

Commit 1b192f7

Browse files
committed
adding some more answers
1 parent d89626a commit 1b192f7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

51 N-Queens.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ var helper = function(n, row, columnForRow, res){
4040

4141
var isValid = function(row, columnForRow){
4242
for(var i = 0; i < row; i++){
43+
// 1. don't have to worry about values on the same column since it will onnly be set once
44+
// 2. same column, columnForRow[row] === columnForRow[i]
45+
// 3. checking both left and right diagonal, Math.abs(columnForRow[row] - columnForRow[i]) === row - i
46+
// Math.abs(columnForRow[row] - columnForRow[i]) is checking both left and right diagonal
4347
if(columnForRow[row] === columnForRow[i] || Math.abs(columnForRow[row] - columnForRow[i]) === row - i){
4448
return false;
4549
}

0 commit comments

Comments
 (0)