Posted onEdited onInLeetCodeDisqus: Symbols count in article: 1.1kReading time ≈1 mins.
backtracking O(n!) time O(n) space There is N possibilities to put the first queen, not more than N * (N - 2) to put the second one, not more than N * (N - 2) * (N - 4) for the third one etc. In total that results in O(n!) time complexity. 按row去dfs,只需统计col以及两个方向的斜边即可