| 33 | } |
| 34 | } |
| 35 | public static boolean isValid(List<String> list, int row, int column, int n){ |
| 36 | if(row > 0){ |
| 37 | String cmp = list.get(row - 1); |
| 38 | for(int i = 0; i < row; i++) |
| 39 | if(list.get(i).charAt(column) == 'Q') return false; |
| 40 | int tempRow = row; |
| 41 | int tempCol = column; |
| 42 | while(--tempRow >= 0 && --tempCol >= 0){ |
| 43 | if(list.get(tempRow).charAt(tempCol) == 'Q') return false; |
| 44 | } |
| 45 | tempRow = row; |
| 46 | tempCol = column; |
| 47 | while(--tempRow >= 0 && ++tempCol <= n-1) |
| 48 | if(list.get(tempRow).charAt(tempCol) == 'Q') return false; |
| 49 | } |
| 50 | return true; |
| 51 | } |
| 52 | private static String createQueen(int n, int index){ |
| 53 | StringBuilder sb = new StringBuilder(); |
| 54 | int i = 0; |