here is my non-recursive approach:

class Solution:

# @param {integer} n

# @return {integer}

def totalNQueens(self, n):

mask, sum = (1<<n)-1, 0

stack = [[0,0,0,mask]]

while len(stack) > 0 :

col, left, right, pos = stack.pop()

if col == mask: sum += 1

elif pos:

p = pos & (-pos)

pos -= p

stack.append([col, left, right, pos])

col,left, right = col|p, (left|p)<<1,(right|p)>>1

stack.append([col,left, right, mask&~(col|left|right)])

return sum