(二分搜索,分治法) leetcode 74. Search a 2D Matrix, 240. II, (hash Table, Binary Search) 981. Time Based Key...

題意:每行都是從小到大排好序的,且 每行第一個數比前一行最後的一個數大。 解法一:將一個二維數組當作一維數組來進行二分搜索,則left索引爲0,right索引爲 row*col - 1; 再將這個一維數組中的座標映射到二維數組中, 即matrix[mid/col][mid%col]. class Solution { public: bool searchMatrix(vector<vec
相關文章
相關標籤/搜索