GeezerVison is showing github.com — 223_Rectangle_Area · dolphintear/leetcode-1@b173c58
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: README.md +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -86,6 +86,7 @@ Also, there are open source implementations for basic data structs and algorithm | 86 | 86 | | 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/219_Contains_Duplicate_II.py) | 1. Brute force<br> 2. Maintenance a set that contains previous k numbers, and check if curr in set | | 87 | 87 | | 220 | [Contains Duplicate III](https://leetcode.com/problems/contains-duplicate-iii/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/220_Contains_Duplicate_III.py) | 1. Sort and binary Search <br>2. Bucket sort | | 88 | 88 | | 221 | [Maximal Square](https://leetcode.com/problems/maximal-square/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/221_Maximal_Square.py) | 1. Brute force<br> 2. dp[i][j] = min(dp[i-1][j], dp[i-1][j-1], dp[i][j-1]) + 1, O(mn) and O(mn)<br>3. dp[j] = min([j], dp[j-1], prev) + 1, O(mn) and O(n)| | | 89 | +| 223 | [Rectangle Area](https://leetcode.com/problems/rectangle-area/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/223_Rectangle_Area.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/223_Rectangle_Area.java) | Rectangle A + B - common area, O(1) and O(1) | | 89 | 90 | | 228 | [Summary Ranges](https://leetcode.com/problems/summary-ranges/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/228_Summary_Ranges.py) | Detect start and jump, O(n) and O(1) | | 90 | 91 | | 236 | [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/236_Lowest_Common_Ancestor_of_a_Binary_Tree.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/236_Lowest_Common_Ancestor_of_a_Binary_Tree.java) | 1. Recursive check left, val and right, LCA is the split paths in tree, O(n) and O(n)<br>2. Store parents during traversing tree, reverse check their lowest common parent, O(n) and O(n) | | 91 | 92 | | 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/238_Product_of_Array_Except_Self.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/238_Product_of_Array_Except_Self.java) | The ans is [0,i -1] * [i+1, len- 1]. We can twice for left and right (reverse), O(n) and O(n) | | |
Collapse file Copy file name to clipboard +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +class Solution { | | 2 | + public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { | | 3 | + // https://leetcode.com/problems/rectangle-area/discuss/62149/Just-another-short-way | | 4 | + // Possible overlap area | | 5 | + int left = Math.max(A, E), right = Math.max(Math.min(C, G), left); | | 6 | + int bottom = Math.max(B, F), top = Math.max(Math.min(D, H), bottom); | | 7 | + return (C - A) * (D - B) - (right - left) * (top - bottom) + (G - E) * (H - F); | | 8 | + } | | 9 | +} |
Collapse file Copy file name to clipboardExpand all lines: python/223_Rectangle Area.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,4 +20,4 @@ def computeArea(self, A, B, C, D, E, F, G, H): | 20 | 20 | dx = min(C, G) - max(A, E) | 21 | 21 | # overlap length on y | 22 | 22 | dy = min(D, H) - max(B, F) | 23 | | - return result - dx * dy | | 23 | + return result - dx * dy |
Collapse file Copy file name to clipboardExpand all lines: python/674_Longest_Continuous_Increasing_Subsequence.py +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,8 +10,7 @@ def findLengthOfLCIS(self, nums): | 10 | 10 | for i in range(len(nums) - 1): | 11 | 11 | if nums[i] < nums[i + 1]: | 12 | 12 | curr += 1 | 13 | | - if curr >= ans: | 14 | | - ans = curr | | 13 | + ans = max(ans, curr) | 15 | 14 | else: | 16 | 15 | curr = 1 | 17 | 16 | return ans |
|