51. N-Queens

# Hard

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

Last updated

Was this helpful?