From b7f2724829d83fd20b7a651fc7d777ba02ce34a1 Mon Sep 17 00:00:00 2001 From: juan Date: Thu, 30 Jun 2022 09:52:25 +0800 Subject: [PATCH] vault backup: 2022-06-30 09:52:25 --- CS notes/pages/Leetcode Search-a-2D-Matrix.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CS notes/pages/Leetcode Search-a-2D-Matrix.md b/CS notes/pages/Leetcode Search-a-2D-Matrix.md index e494bb4..eda580f 100644 --- a/CS notes/pages/Leetcode Search-a-2D-Matrix.md +++ b/CS notes/pages/Leetcode Search-a-2D-Matrix.md @@ -62,6 +62,7 @@ Binary search algorithm, with simple 2-d to 1-d conversion > And use: > - l = mid + 1 > - r = mid - 1 +> Init r as m * n - 1 to avoid mid being OOB. ### Solution ==note how I calculated the mid, i, j, and how I changed r and l== @@ -72,6 +73,7 @@ public: int m = matrix.size(); int n = matrix[0].size(); int l = 0; + // set r to len - 1 to avoid mid being bigger than len. int r = m * n - 1; int i; // the key to speed is to precaculate i and j, to save time. int j;