@@ -9,11 +9,6 @@ pub enum MatrixError {
99
1010/// Checks if the given matrix (vector of vectors) is sorted row-wise and column-wise.
1111///
12- /// A matrix is considered sorted if
13- ///
14- /// * Each row is sorted in non-decreasing order.
15- /// * Each column is sorted in non-decreasing order.
16- ///
1712/// # Arguments
1813///
1914/// * `matrix` - A vector of vectors representing the matrix to check.
@@ -22,10 +17,6 @@ pub enum MatrixError {
2217///
2318/// Returns `true` if the matrix is sorted both row-wise and column-wise. Otherwise, returns `false`.
2419fn is_sorted ( matrix : & [ Vec < isize > ] ) -> bool {
25- if matrix. is_empty ( ) || matrix. iter ( ) . all ( |row| row. is_empty ( ) ) {
26- return true ;
27- }
28-
2920 let rows = matrix. len ( ) ;
3021 let cols = matrix[ 0 ] . len ( ) ;
3122
@@ -72,10 +63,6 @@ pub fn saddleback_search(
7263 element : isize ,
7364 check_sorted : bool ,
7465) -> Result < Option < ( usize , usize ) > , MatrixError > {
75- if check_sorted && !is_sorted ( matrix) {
76- return Err ( MatrixError :: NotSorted ) ;
77- }
78-
7966 if matrix. is_empty ( ) || matrix. iter ( ) . all ( |row| row. is_empty ( ) ) {
8067 return Ok ( None ) ;
8168 }
@@ -84,6 +71,10 @@ pub fn saddleback_search(
8471 return Err ( MatrixError :: NonRectangularInput ) ;
8572 }
8673
74+ if check_sorted && !is_sorted ( matrix) {
75+ return Err ( MatrixError :: NotSorted ) ;
76+ }
77+
8778 let mut left_index = 0 ;
8879 let mut right_index = matrix[ 0 ] . len ( ) - 1 ;
8980
0 commit comments