MCPcopy Create free account
hub / github.com/careercup/ctci / isSquare

Method isSquare

java/Chapter 18/Question18_11/Question.java:38–59  ·  view source on GitHub ↗
(int[][] matrix, int row, int col, int size)

Source from the content-addressed store, hash-verified

36 }
37
38 private static boolean isSquare(int[][] matrix, int row, int col, int size) {
39 // Check top and bottom border.
40 for (int j = 0; j < size; j++){
41 if (matrix[row][col+j] == 1) {
42 return false;
43 }
44 if (matrix[row+size-1][col+j] == 1) {
45 return false;
46 }
47 }
48
49 // Check left and right border.
50 for (int i = 1; i < size - 1; i++) {
51 if (matrix[row+i][col] == 1){
52 return false;
53 }
54 if (matrix[row+i][col+size-1] == 1) {
55 return false;
56 }
57 }
58 return true;
59 }
60
61 public static void main(String[] args) {
62 int[][] matrix = AssortedMethods.randomMatrix(7, 7, 0, 1);

Callers 1

findSquareWithSizeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected