MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / isSafe

Method isSafe

-51-N_Queens/Code.java:4–29  ·  view source on GitHub ↗
(int[][] board, int row, int col)

Source from the content-addressed store, hash-verified

2
3class Solution {
4 public boolean isSafe(int[][] board, int row, int col) {
5 int x = row, y = col;
6
7 // Check left side of the current row
8 while (y >= 0) {
9 if (board[x][y--] == 1)
10 return false;
11 }
12
13 // Check upper diagonal on left side
14 y = col;
15 while (x < board.length && y >= 0) {
16 if (board[x++][y--] == 1)
17 return false;
18 }
19
20 // Check lower diagonal on left side
21 x = row;
22 y = col;
23 while (x >= 0 && y >= 0) {
24 if (board[x--][y--] == 1)
25 return false;
26 }
27
28 return true;
29 }
30
31 public void addSol(int[][] board, int n, List<List<String>> ans) {
32 List<String> arr = new ArrayList<>();

Callers 1

solveMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected