Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1b192f7

Browse files
committed
adding some more answers
1 parentd89626a commit1b192f7

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
varisValid=function(row,columnForRow){
4242
for(vari=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
returnfalse;
4549
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp