Solved LeetCode program · 978 of 1,000
#1351 · Count Negative Numbers in a Sorted Matrix
Original English source
Keep a shared grid holding 4, 3, 2, -1, 3, 2, 1, -1, 1, 1, -1, -2, -1, -1, -2, and -3. Keep a shared first of 0. Keep a shared low of 0. Keep a shared high of 0. Keep a shared middle of 0.
To scan from line (a whole number). Set low to 0. Set high to 3. Set first to 4.
Repeat while low is at most high.
Set middle to (low plus high) divided by 2. The value is item (line times 4 plus middle) of grid. If value is less than 0, set first to middle, set high to middle minus 1. If value is at least 0, set low to middle plus 1.
The answer is 0.
For every line from 0 to 3.
Scan from line. Increase answer by 4 minus first.
Show answer.
Expected stdout
8