51.N-Queens

image.png

因为是按行排列的(for循环),所以我们不需要标记行,只需要标记列col和主副对角线diag1和diag2

P.S.今天看到一个比较正解的说法,关于递归和回溯:
It would be really interesting to see this backtracking done in an iterative way...
Backtracking = stack + iteration
回溯 = 栈+递归
确乎如此!

你可能感兴趣的:(51.N-Queens)