LeetCode weekly contest 176
YoungForest · https://youngforest.github.io/en/2020/02/16/LeetCode-weekly-contest-176/
On this page · 4 sections
| Rank | Name | Score | Finish Time | Q1 (3) | Q2 (5) | Q3 (5) | Q4 (6) |
|---|---|---|---|---|---|---|---|
| 306 / 8105 | YoungForest | 19 | 1:36:07 | 0:02:47 | 0:23:09 | 0:54:53 1 | 1:26:07 1 |
In this contest I finally got AC at the last moment, which was extremely thrilling. Since joining the students in the China region, it has been hard for my weekly contest rank to enter the top 200. For example, this time I dropped from 229 to 306. I have to admit that domestic competition is fierce.
The main reason for the lower ranking was that I spent a lot of time debugging and trying things on the third problem, and almost had no time left to implement the last one. The recent lack of practice has also caused my debug ability and one-pass bug-free ability to drop sharply.
1351. Count Negative Numbers in a Sorted Matrix
Using the fact that both rows and columns are sorted, we can count in O(m + n).
It is similar to search-a-2d-matrix-ii.
Time complexity: O(m + n),
space complexity: O(1).
1 | class Solution { |
1352. Product of the Last K Numbers
Record the position of the last zero and the cumulative product. Determine whether the last K numbers contain a zero. If not, divide the last cumulative product by the product before the k-th number from the end.
Time complexity:
- add: O(1)
- getProduct: O(1)
Space complexity: O(N)
1 | class ProductOfNumbers { |
1353. Maximum Number of Events That Can Be Attended
Greedy strategy.
Always attend the event with the earliest ending time.
Time complexity: O(N log N),
space complexity: O(N).
1 | class Solution { |
1354. Construct Target Array With Multiple Sums
This problem looks hard, but once you discover that the result of each replace operation is always the largest number, you can reverse the process from the final array back to the initial array.
Time complexity: O(N log N max_number)
Space complexity: O(N).
1 | class Solution { |