LeetCode Biweekly Contest 52
| Rank | Name | Score | Finish Time | Q1 (3) | Q2 (5) | Q3 (5) | Q4 (6) |
|---|---|---|---|---|---|---|---|
| 2217 / 10364 | YoungForest | 12 | 0:51:47 | 0:05:11 | 0:51:47 | 0:29:51 | null |
1859. Sorting the Sentence
Use python for string problems. Although the problem is not hard, just splitting the string and sorting according to the specified content, the implementation is still more complex than expected. Fortunately, Python has many convenient APIs and data structures that can be used flexibly.
1 | class Solution: |
Time complexity: O(s.length),
space complexity: O(s.length).
1860. Incremental Memory Leak
Originally I wanted to solve it in O(1) using the arithmetic-series sum and solving equations. But in reality, implementation and equation solving were still too complicated. I did not finish it in the end. After finishing the third problem, I came back and calculated the brute-force time complexity: O(sqrt(2^32)) = 65536. Surprisingly low. Sure enough, the second problem should not be overcomplicated; direct brute force would have been much better.
Brute-force simulation of the memory allocation process described in the problem.
1 | class Solution { |
Time complexity: O(sqrt(memory1 + memory2)),
space complexity: O(1).
1861. Rotating the Box
After understanding the essence of falling, you can see that it is only necessary to count how many stones exist between the left side of each obstacle/ground and the previous obstacle.
1 | class Solution { |
Time complexity: O(m * n),
space complexity: O(m * n).
1862. Sum of Floored Pairs
I did not have a good idea. First I tried the brute-force solution, enumerating all pairs:
1 | class Solution: |
Time complexity: O(N^2), TLE,
space complexity: O(1).
Then I tried optimizing with binary search, finding the multiple ranges for each number.
1 | class Solution { |
Time complexity: O(N log N log N). Although there are two nested loops, the second is actually a harmonic series. Still, it TLE’d.
Space complexity: O(1).
I should just read LingShen’s solution: