vault backup: 2022-06-30 09:52:25

This commit is contained in:
juan 2022-06-30 09:52:25 +08:00
parent d5c38b979f
commit b7f2724829

View file

@ -62,6 +62,7 @@ Binary search algorithm, with simple 2-d to 1-d conversion
> And use: > And use:
> - l = mid + 1 > - l = mid + 1
> - r = mid - 1 > - r = mid - 1
> Init r as m * n - 1 to avoid mid being OOB.
### Solution ### Solution
==note how I calculated the mid, i, j, and how I changed r and l== ==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 m = matrix.size();
int n = matrix[0].size(); int n = matrix[0].size();
int l = 0; int l = 0;
// set r to len - 1 to avoid mid being bigger than len.
int r = m * n - 1; int r = m * n - 1;
int i; // the key to speed is to precaculate i and j, to save time. int i; // the key to speed is to precaculate i and j, to save time.
int j; int j;