Java Time Limit Exceeded 'cause of matrix[0].length


  • 0
    S

    I got a Time Limit Exceeded for the test case [[1]], 0
    I tried out a few test myself, i believe there is something unusual with matrix[0]

    Any ideas?

    My code:

    public class Solution {
        public boolean searchMatrix(int[][] matrix, int target) {
            int i = matrix.length;
            int j = 0;
            if (i > 0) {
                j = matrix[0].length;
            }
            // j = 1; if i un-comment this, it will pass
            while (i < j) {
                // my code
            }
            
            return 1 == j; // returns true on test case [[1]], 0
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.