# 51. N-Queens

{% hint style="danger" %}
Think it as permutation, add one eligible element，continue picking next, but don't forget to remove it. This can be regarded as Bruce Force, trying all cases eventually.

只要结果的长度都是n的数组，那么就是“排列”的方法。横着、纵着、斜都会互相attack。
{% endhint %}

### Solution:

1. `helper function`, similar as **@60**, but adding one judge if element is valid.
2. `isValid function`, new adding element must not conflict with existed elements. Return **True** or **False**.
3. stop condition in `helper function` is to length, we transfer numerical array to string list by the way

Conditions of isValid:

* column\_A != column\_B
* row\_A + column\_A != row\_B + column\_B
* row\_A - column\_A != row\_B - column\_B
