File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 68
68
| 70 | [ Climbing Stairs] ( https://leetcode.com/problems/climbing-stairs ) | [ ![ Java] ( assets/java.png )] ( src/ClimbingStairs.java ) [ ![ Python] ( assets/python.png )] ( python/climbing_stairs.py ) | |
69
69
| 71 | [ Simplify Path] ( https://leetcode.com/problems/simplify-path ) | [ ![ Java] ( assets/java.png )] ( src/SimplifyPath.java ) | |
70
70
| 73 | [ Set Matrix Zeroes] ( https://leetcode.com/problems/set-matrix-zeroes ) | [ ![ Java] ( assets/java.png )] ( src/SetMatrixZeroes.java ) | |
71
+ | 74 | [ Search a 2D Matrix] ( https://leetcode.com/problems/search-a-2d-matrix ) | [ ![ Java] ( assets/java.png )] ( src/SearchA2DMatrix.java ) | |
71
72
| 83 | [ Remove Duplicates from Sorted List] ( https://leetcode.com/problems/remove-duplicates-from-sorted-list ) | [ ![ Java] ( assets/java.png )] ( src/RemoveDuplicatesFromSortedList.java ) [ ![ Python] ( assets/python.png )] ( python/remove_duplicates_from_linked_list.py ) | |
72
73
| 88 | [ Merge Sorted Array] ( https://leetcode.com/problems/merge-sorted-array ) | [ ![ Java] ( assets/java.png )] ( src/MergeSortedArray.java ) [ ![ Python] ( assets/python.png )] ( python/merge_sorted_array.py ) | |
73
74
| 94 | [ Binary Tree Inorder Traversal] ( https://leetcode.com/problems/binary-tree-inorder-traversal/ ) | [ ![ Java] ( assets/java.png )] ( src/BinaryTreeInorderTraversal.java ) [ ![ Python] ( assets/python.png )] ( python/binary_tree_inorder_traversal.py ) | |
Original file line number Diff line number Diff line change
1
+ // https://leetcode.com/problems/search-a-2d-matrix
2
+ // T: O(log(m*n))
3
+ // S: O(1)
4
+
5
+ public class SearchA2DMatrix {
6
+ public boolean searchMatrix (int [][] matrix , int target ) {
7
+ final int rows = matrix .length , columns = matrix [0 ].length ;
8
+ int left = 0 , right = rows * columns - 1 , middle ;
9
+ while (left <= right ) {
10
+ middle = left + (right - left ) / 2 ;
11
+ if (matrix [middle / columns ][middle % columns ] == target ) return true ;
12
+ else if (matrix [middle / columns ][middle % columns ] > target ) right = middle - 1 ;
13
+ else left = middle + 1 ;
14
+ }
15
+ return false ;
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments