File tree 3 files changed +52
-0
lines changed
solution/0200-0299/0240.Search a 2D Matrix II
3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,25 @@ class Solution {
95
95
}
96
96
```
97
97
98
+ ### ** TypeScript**
99
+
100
+ ``` ts
101
+ function searchMatrix(matrix : number [][], target : number ): boolean {
102
+ let m = matrix .length , n = matrix [0 ].length ;
103
+ let i = m - 1 , j = 0 ;
104
+ while (i >= 0 && j < n ) {
105
+ let cur = matrix [i ][j ];
106
+ if (cur == target ) return true ;
107
+ if (cur > target ) {
108
+ -- i ;
109
+ } else {
110
+ ++ j ;
111
+ }
112
+ }
113
+ return false ;
114
+ };
115
+ ```
116
+
98
117
### ** C++**
99
118
100
119
``` cpp
Original file line number Diff line number Diff line change @@ -83,6 +83,25 @@ class Solution {
83
83
}
84
84
```
85
85
86
+ ### ** TypeScript**
87
+
88
+ ``` ts
89
+ function searchMatrix(matrix : number [][], target : number ): boolean {
90
+ let m = matrix .length , n = matrix [0 ].length ;
91
+ let i = m - 1 , j = 0 ;
92
+ while (i >= 0 && j < n ) {
93
+ let cur = matrix [i ][j ];
94
+ if (cur == target ) return true ;
95
+ if (cur > target ) {
96
+ -- i ;
97
+ } else {
98
+ ++ j ;
99
+ }
100
+ }
101
+ return false ;
102
+ };
103
+ ```
104
+
86
105
### ** C++**
87
106
88
107
``` cpp
Original file line number Diff line number Diff line change
1
+ function searchMatrix ( matrix : number [ ] [ ] , target : number ) : boolean {
2
+ let m = matrix . length , n = matrix [ 0 ] . length ;
3
+ let i = m - 1 , j = 0 ;
4
+ while ( i >= 0 && j < n ) {
5
+ let cur = matrix [ i ] [ j ] ;
6
+ if ( cur == target ) return true ;
7
+ if ( cur > target ) {
8
+ -- i ;
9
+ } else {
10
+ ++ j ;
11
+ }
12
+ }
13
+ return false ;
14
+ } ;
You can’t perform that action at this time.
0 commit comments