rewrite leetcode nQueens