public boolean searchMatrix(int[][] matrix, int target) {

    int head = 0;
    int tail = matrix.length*matrix[0].length - 1;
    int colm = matrix[0].length;
    
    while(head <= tail) {
    	
    	int mid = head + (tail - head) / 2;
    	int row = mid / colm;
    	int col = mid % colm;

    	if(matrix[row][col] == target) {
    		return true;
    	}
    	if(matrix[row][col] < target) {
    		head = mid + 1; // !!! important
    	} else {
    		tail = mid - 1; // !!! important
    	}
    	
    }
    
    return false;
  }