LeetCode weekly contest 139
YoungForest · https://youngforest.github.io/en/2019/06/03/LeetCode-weekly-contest-139/
On this page · 4 sections
| Rank | Name | Score | Finish Time | Q1 (4) | Q2 (5) | Q3 (6) | Q4 (8) |
|---|---|---|---|---|---|---|---|
| 855 / 3985 | YoungForest | 10 | 1:03:50 | 0:53:00 | 1:03:50 | solved after the contest | null |
When I got up on Sunday, it was already past 11, so I joined the contest 40 minutes late. I solved the first two problems smoothly. I took some detours on the third problem and only solved it after the contest. If there had been enough time, solving the third problem should not have been an issue.
1071. Greatest Common Divisor of Strings
Intuition:
This problem is equivalent to finding the greatest common divisor of two numbers.
The length of Greatest Common Divisor must be equal to the greatest common divisor or 0.
A simple proof is as follows:
Suppose the answer length is x. Since str1 is composed of x, x must be a divisor of str1.length. Similarly, it is also a divisor of str2.length.
If x is not the greatest common divisor but can form both str1 and str2, then the greatest common divisor must also be able to form both str1 and str2.
Time complexity: O(log N)
Space complexity: O(N)
1 | class Solution { |
1072. Flip Columns For Maximum Number of Equal Rows
Intuition:
Find the maximum number of complementary rows.
Time complexity: O(matrix.length * matrix[0].length)
Space complexity: O(matrix.length * matrix[0].length)
1 | class Solution { |
1073. Adding Two Negabinary Numbers
Intuition:
Imitate binary addition. The difference is that the carry may be -1, 1, or 0.
Time complexity: O(max(arr.size(), arr.size()))
Space complexity: O(max(arr.size(), arr.size()))
1 | class Solution { |