LeetCode weekly contest 135
| Rank | Name | Score | Finish Time | Q1 (4) | Q2 (5) | Q3 (5) | Q4 (5) |
|---|---|---|---|---|---|---|---|
| 70 / 3635 | YoungForest | 15 | 1:34:07 | 0:07:28 | 0:16:45 | null | 1:29:07 (1) |
This Sunday was a workday in China, so the number of people participating in LeetCode weekly contest directly dropped by 1,000, which shows how enthusiastic domestic participants are about this contest. Chinese contestants are also generally among the strongest in the world. So this time I ranked 70 and entered the top 200 for the first time. Besides the credit for racing against the clock and AC’ing the last problem before the end, there was also the reason that fewer strong contestants participated.
5051. Valid Boomerang
Intuition:
Divide it into two parts: checking distinctness and checking not in a straight line.
Three collinear points can be judged directly by slope.
Time complexity: O(1)
Space complexity: O(1)
1 | class Solution { |
Tricks found in discuss:
- You can directly use whether the area is 0 to judge both distinctness and collinearity. The area formula is computed with cross product.
- When judging slope, converting division to multiplication is better. Then there is no need to check distinctness in advance.
My solution has a division-by-zero problem,
but it can still pass test cases like [[1,2],[1,1],[2,1]].
Thinking carefully, C++ floating-point division follows the IEEE 754 standard, so the result is +infinity. Naturally, the comparison produces a not-equal result.
1038. Binary Search Tree to Greater Sum Tree
1 | /** |
1039. Minimum Score Triangulation of Polygon
Intuition:
DP.
For an n-sided polygon, there can be a straight line that divides it into k-sided and n-k-sided polygons.
This line must be one side of a triangle.
Then enumerate the position of the other point and update the minimum value.
Time complexity: O(n ^ 3),
Space complexity: O(n ^ 2)
1 | class Solution { |
1040. Moving Stones Until Consecutive II
Time complexity: O(n log n), because there is a sort.
Space complexity: O(1)
1 | class Solution { |