Why my code is time exceeded (C++)


  • 0
    G

    Not sure why this happens...

    class Solution {
    public:
    	bool searchMatrix(vector<vector<int>> matrix, int target) {
    		int row = matrix.size();
    		int column = matrix.front().size();
    
    		int _row = 0; int _column = column - 1;
    		while (_row < row && _column >= 0){
    			int tmp = matrix[_row][_column];
    			if (tmp == target) return true;
    			if (tmp > target) --_column;
    			if (tmp < target) ++_row;
    		}
    		return false;
    	};
    };
    

  • 0
    D

    I have submited it, and it passed all test case


  • 0
    G

    Find the problem...

    The parameter matrix passing into the function should be a reference type instead of a value.

    Sorry for the typo...


  • 0
    G

    @dyungwang Thanks m8. I find the problem which is a typo ...


Log in to reply
 

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