Facebook
From Eratic Rhinoceros, 7 Years ago, written in Java.
">

A PHP Error was encountered

Severity: Notice

Message: Trying to access array offset on value of type bool

Filename: view/view.php

Line Number: 33

from

A PHP Error was encountered

Severity: Notice

Message: Trying to access array offset on value of type bool

Filename: view/view.php

Line Number: 33

- view diff
Embed
Download Paste or View Raw
Hits: 342
  1.   public static int solution(int[][] A) {
  2.     // write your code in Java SE 8
  3.     int countSaddlePoints = 0;
  4.  
  5.     for (int P = 1; P < A.length - 1; P++) {
  6.       for (int Q = 1; Q < A[P].length - 1; Q++) {
  7.        
  8.         if (    A[P][Q - 1] > A[P][Q] && A[P][Q] < A[P][Q + 1] &&
  9.                 A[P - 1][Q] < A[P][Q] && A[P][Q] > A[P + 1][Q]) {
  10.          
  11.           countSaddlePoints++;
  12.         }
  13.         else if ( A[P][Q - 1] < A[P][Q] && A[P][Q] > A[P][Q + 1] &&
  14.                   A[P - 1][Q] > A[P][Q] && A[P][Q] < A[P + 1][Q]) {
  15.          
  16.           countSaddlePoints++;
  17.         }
  18.       }
  19.     }
  20.  
  21.     return countSaddlePoints;
  22.   }
  23.