Skip to content

Commit 6467289

Browse files
committed
Mar-10
1 parent 6a13875 commit 6467289

7 files changed

+411
-33
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
3737
| Status | List | Progress | Notes |
3838
| ----- | ----- | ----- | ----- |
3939
| [24%] | [leetcode-discuss.md](./list/leetcode-discuss.md) | 13/54 | - |
40-
| [48%] | [leetcode-google.md](./list/leetcode-google.md) | 227/471 | 2 vips |
40+
| [48%] | [leetcode-google.md](./list/leetcode-google.md) | 228/471 | 2 vips |
4141
| [52%] | [leetcode-75.md](./list/leetcode-75.md) | 39/75 | - |
4242
| [52%] | [leetcode-topics.md](./list/leetcode-topics.md) | 75/144 | - |
4343
| [86%] | [leetcode-top-interview-150.md](./list/leetcode-top-interview-150.md) | 130/150 | - |
@@ -53,9 +53,9 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
5353
| [] | [leetcode-top-100-liked.md](./list/leetcode-top-100-liked.md) | 100/100 | - |
5454
| [] | [leetcode101.md](./list/leetcode101.md) | 183/184 | 1 vip |
5555
| [🔲] | [9c-basic.md](./list/9c-basic.md) | 14/129 | 3 vips |
56-
| [🔲] | [灵茶山艾府.md](./list/灵茶山艾府.md) | 49/2208 | 3 vips |
56+
| [🔲] | [灵茶山艾府.md](./list/灵茶山艾府.md) | 50/2208 | 3 vips |
5757

58-
**Solved**: 580 problems
58+
**Solved**: 582 problems
5959

6060
## 类型/Category
6161

@@ -100,7 +100,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
100100

101101
## Math
102102

103-
| Link | Problem(37) | Solution | Tag | Time | Space | Ref |
103+
| Link | Problem(38) | Solution | Tag | Time | Space | Ref |
104104
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
105105
| [Leetcode-415](https://leetcode.com/problems/add-strings/) | Add Strings | [c++](./leetcode/415.add-strings.cpp), [python3](./leetcode/415.add-strings.py) | Math | O\(N\) | O\(1\) | - |
106106
| [Leetcode-2](https://leetcode.com/problems/add-two-numbers/) | Add Two Numbers | [c++](./leetcode/2.add-two-numbers.cpp), [python3](./leetcode/2.add-two-numbers.py) | Math | O\(N \+ M\) | O\(1\) | - |
@@ -126,6 +126,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
126126
| [Leetcode-12](https://leetcode.com/problems/integer-to-roman/) | Integer To Roman | [c++](./leetcode/12.integer-to-roman.cpp), [python3](./leetcode/12.integer-to-roman.py) | Math | O\(N\) | O\(1\) | - |
127127
| [Leetcode-973](https://leetcode.com/problems/k-closest-points-to-origin/) | K Closest Points To Origin | [c++](./leetcode/973.k-closest-points-to-origin.cpp), [python3](./leetcode/973.k-closest-points-to-origin.py) | Math | O\(NlogN\) | O\(K\) | - |
128128
| [Leetcode-149](https://leetcode.com/problems/max-points-on-a-line/) | Max Points On A Line | [c++](./leetcode/149.max-points-on-a-line.cpp), [python3](./leetcode/149.max-points-on-a-line.py) | Math | O\(N^2\) | O\(N\) | - |
129+
| [Leetcode-1610](https://leetcode.com/problems/maximum-number-of-visible-points/) | Maximum Number Of Visible Points | [c++](./leetcode/1610.maximum-number-of-visible-points.cpp), [python3](./leetcode/1610.maximum-number-of-visible-points.py) | Math | O\(NlogN\) | O\(N\) | - |
129130
| [Leetcode-462](https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/) | Minimum Moves To Equal Array Elements II | [c++](./leetcode/462.minimum-moves-to-equal-array-elements-ii.cpp), [python3](./leetcode/462.minimum-moves-to-equal-array-elements-ii.py) | Math | O\(NlogN\) | O\(1\) | - |
130131
| [Leetcode-43](https://leetcode.com/problems/multiply-strings/) | Multiply Strings | [c++](./leetcode/43.multiply-strings.cpp), [python3](./leetcode/43.multiply-strings.py) | Math | O\(NM\) | O\(N\+M\) | - |
131132
| [Leetcode-326](https://leetcode.com/problems/power-of-three/) | Power Of Three | [c++](./leetcode/326.power-of-three.cpp), [python3](./leetcode/326.power-of-three.py) | Math | O\(1\) | O\(1\) | - |
@@ -473,7 +474,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
473474

474475
## Hash Table
475476

476-
| Link | Problem(89) | Solution | Tag | Time | Space | Ref |
477+
| Link | Problem(90) | Solution | Tag | Time | Space | Ref |
477478
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
478479
| [Leetcode-721](https://leetcode.com/problems/accounts-merge/) | Accounts Merge | [c++](./leetcode/721.accounts-merge.cpp), [python3](./leetcode/721.accounts-merge.py) | Hash Table | O\(MlogM\) | O\(N\) | - |
479480
| [Leetcode-863](https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree/) | All Nodes Distance K In Binary Tree | [c++](./leetcode/863.all-nodes-distance-k-in-binary-tree.cpp), [python3](./leetcode/863.all-nodes-distance-k-in-binary-tree.py) | Hash Table | O\(N\) | O\(N\) | - |
@@ -485,6 +486,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
485486
| [Leetcode-525](https://leetcode.com/problems/contiguous-array/) | Contiguous Array | [c++](./leetcode/525.contiguous-array.cpp), [python3](./leetcode/525.contiguous-array.py) | Hash Table | O\(N\) | O\(N\) | - |
486487
| [Leetcode-2953](https://leetcode.com/problems/count-complete-substrings/) | Count Complete Substrings | [c++](./leetcode/2953.count-complete-substrings.cpp), [python3](./leetcode/2953.count-complete-substrings.py) | Hash Table | O\(N\) | O\(N\) | - |
487488
| [Leetcode-2364](https://leetcode.com/problems/count-number-of-bad-pairs/) | Count Number Of Bad Pairs | [c++](./leetcode/2364.count-number-of-bad-pairs.cpp), [python3](./leetcode/2364.count-number-of-bad-pairs.py) | Hash Table | O\(N\) | O\(N\) | - |
489+
| [Leetcode-3306](https://leetcode.com/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/) | Count Of Substrings Containing Every Vowel And K Consonants II | [c++](./leetcode/3306.count-of-substrings-containing-every-vowel-and-k-consonants-ii.cpp), [python3](./leetcode/3306.count-of-substrings-containing-every-vowel-and-k-consonants-ii.py) | Hash Table | O\(N\) | O\(N\) | - |
488490
| [Leetcode-697](https://leetcode.com/problems/degree-of-an-array/) | Degree Of An Array | [c++](./leetcode/697.degree-of-an-array.cpp), [python3](./leetcode/697.degree-of-an-array.py) | Hash Table | O\(N\) | O\(N\) | - |
489491
| [Leetcode-1110](https://leetcode.com/problems/delete-nodes-and-return-forest/) | Delete Nodes And Return Forest | [c++](./leetcode/1110.delete-nodes-and-return-forest.cpp), [python3](./leetcode/1110.delete-nodes-and-return-forest.py) | Hash Table | O\(N\) | O\(N\) | - |
490492
| [Leetcode-2349](https://leetcode.com/problems/design-a-number-container-system/) | Design A Number Container System | [c++](./leetcode/2349.design-a-number-container-system.cpp), [python3](./leetcode/2349.design-a-number-container-system.py) | Hash Table | O\(LogN\) | O\(N\) | - |
@@ -734,12 +736,13 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
734736

735737
## Sliding Window
736738

737-
| Link | Problem(58) | Solution | Tag | Time | Space | Ref |
739+
| Link | Problem(60) | Solution | Tag | Time | Space | Ref |
738740
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
739741
| [Leetcode-3206](https://leetcode.com/problems/alternating-groups-i/) | Alternating Groups I | [c++](./leetcode/3206.alternating-groups-i.cpp), [python3](./leetcode/3206.alternating-groups-i.py) | Sliding Window | O\(N\) | O\(1\) | - |
740742
| [Leetcode-3208](https://leetcode.com/problems/alternating-groups-ii/) | Alternating Groups II | [c++](./leetcode/3208.alternating-groups-ii.cpp), [python3](./leetcode/3208.alternating-groups-ii.py) | Sliding Window | O\(N\) | O\(1\) | - |
741743
| [Leetcode-220](https://leetcode.com/problems/contains-duplicate-iii/) | Contains Duplicate III | [c++](./leetcode/220.contains-duplicate-iii.cpp), [python3](./leetcode/220.contains-duplicate-iii.py) | Sliding Window | O\(N\) | O\(N\) | - |
742744
| [Leetcode-2953](https://leetcode.com/problems/count-complete-substrings/) | Count Complete Substrings | [c++](./leetcode/2953.count-complete-substrings.cpp), [python3](./leetcode/2953.count-complete-substrings.py) | Sliding Window | O\(N\) | O\(N\) | - |
745+
| [Leetcode-3306](https://leetcode.com/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/) | Count Of Substrings Containing Every Vowel And K Consonants II | [c++](./leetcode/3306.count-of-substrings-containing-every-vowel-and-k-consonants-ii.cpp), [python3](./leetcode/3306.count-of-substrings-containing-every-vowel-and-k-consonants-ii.py) | Sliding Window | O\(N\) | O\(N\) | - |
743746
| [Leetcode-1652](https://leetcode.com/problems/defuse-the-bomb/) | Defuse The Bomb | [c++](./leetcode/1652.defuse-the-bomb.cpp), [python3](./leetcode/1652.defuse-the-bomb.py) | Sliding Window | O\(N\) | O\(1\) | - |
744747
| [Leetcode-438](https://leetcode.com/problems/find-all-anagrams-in-a-string/) | Find All Anagrams In A String | [c++](./leetcode/438.find-all-anagrams-in-a-string.cpp), [python3](./leetcode/438.find-all-anagrams-in-a-string.py) | Sliding Window | O\(N\) | O\(K\) | - |
745748
| [Leetcode-658](https://leetcode.com/problems/find-k-closest-elements/) | Find K Closest Elements | [c++](./leetcode/658.find-k-closest-elements.cpp), [python3](./leetcode/658.find-k-closest-elements.py) | Sliding Window | O\(Log\(N \- K\)\) | O\(1\) | - |
@@ -767,6 +770,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
767770
| [Leetcode-718](https://leetcode.com/problems/maximum-length-of-repeated-subarray/) | Maximum Length Of Repeated Subarray | [c++](./leetcode/718.maximum-length-of-repeated-subarray.cpp), [python3](./leetcode/718.maximum-length-of-repeated-subarray.py) | Sliding Window | O\(NM\) | O\(NM\) | - |
768771
| [Leetcode-3090](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences/) | Maximum Length Substring With Two Occurrences | [c++](./leetcode/3090.maximum-length-substring-with-two-occurrences.cpp), [python3](./leetcode/3090.maximum-length-substring-with-two-occurrences.py) | Sliding Window | O\(N\) | O\(N\) | - |
769772
| [Leetcode-1297](https://leetcode.com/problems/maximum-number-of-occurrences-of-a-substring/) | Maximum Number Of Occurrences Of A Substring | [c++](./leetcode/1297.maximum-number-of-occurrences-of-a-substring.cpp), [python3](./leetcode/1297.maximum-number-of-occurrences-of-a-substring.py) | Sliding Window | O\(N\) | O\(N^2\) | - |
773+
| [Leetcode-1610](https://leetcode.com/problems/maximum-number-of-visible-points/) | Maximum Number Of Visible Points | [c++](./leetcode/1610.maximum-number-of-visible-points.cpp), [python3](./leetcode/1610.maximum-number-of-visible-points.py) | Sliding Window | O\(NlogN\) | O\(N\) | - |
770774
| [Leetcode-1456](https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Maximum Number Of Vowels In A Substring Of Given Length | [c++](./leetcode/1456.maximum-number-of-vowels-in-a-substring-of-given-length.cpp), [python3](./leetcode/1456.maximum-number-of-vowels-in-a-substring-of-given-length.py) | Sliding Window | O\(N\) | O\(1\) | - |
771775
| [Leetcode-1423](https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards/) | Maximum Points You Can Obtain From Cards | [c++](./leetcode/1423.maximum-points-you-can-obtain-from-cards.cpp), [python3](./leetcode/1423.maximum-points-you-can-obtain-from-cards.py) | Sliding Window | O\(N\) | O\(1\) | - |
772776
| [Leetcode-2841](https://leetcode.com/problems/maximum-sum-of-almost-unique-subarray/) | Maximum Sum Of Almost Unique Subarray | [c++](./leetcode/2841.maximum-sum-of-almost-unique-subarray.cpp), [python3](./leetcode/2841.maximum-sum-of-almost-unique-subarray.py) | Sliding Window | O\(N\) | O\(N\) | - |
@@ -797,7 +801,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
797801

798802
## Sorting
799803

800-
| Link | Problem(48) | Solution | Tag | Time | Space | Ref |
804+
| Link | Problem(49) | Solution | Tag | Time | Space | Ref |
801805
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
802806
| [Leetcode-15](https://leetcode.com/problems/3sum/) | 3Sum | [c++](./leetcode/15.3sum.cpp), [python3](./leetcode/15.3sum.py) | Sorting | O\(N^2\) | O\(1\) | - |
803807
| [Leetcode-18](https://leetcode.com/problems/4sum/) | 4Sum | [c++](./leetcode/18.4sum.cpp), [python3](./leetcode/18.4sum.py) | Sorting | O\(N^3\) | O\(1\) | - |
@@ -824,6 +828,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
824828
| [Leetcode-3281](https://leetcode.com/problems/maximize-score-of-numbers-in-ranges/) | Maximize Score Of Numbers In Ranges | [c++](./leetcode/3281.maximize-score-of-numbers-in-ranges.cpp), [python3](./leetcode/3281.maximize-score-of-numbers-in-ranges.py) | Sorting | O\(NlogN \+ NlogD\) | O\(1\) | - |
825829
| [Leetcode-2779](https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation/) | Maximum Beauty Of An Array After Applying Operation | [c++](./leetcode/2779.maximum-beauty-of-an-array-after-applying-operation.cpp), [python3](./leetcode/2779.maximum-beauty-of-an-array-after-applying-operation.py) | Sorting | O\(NlogN\) | O\(1\) | - |
826830
| [Leetcode-646](https://leetcode.com/problems/maximum-length-of-pair-chain/) | Maximum Length Of Pair Chain | [c++](./leetcode/646.maximum-length-of-pair-chain.cpp), [python3](./leetcode/646.maximum-length-of-pair-chain.py) | Sorting | O\(NlogN\) | O\(N\) | - |
831+
| [Leetcode-1610](https://leetcode.com/problems/maximum-number-of-visible-points/) | Maximum Number Of Visible Points | [c++](./leetcode/1610.maximum-number-of-visible-points.cpp), [python3](./leetcode/1610.maximum-number-of-visible-points.py) | Sorting | O\(NlogN\) | O\(N\) | - |
827832
| [Leetcode-1235](https://leetcode.com/problems/maximum-profit-in-job-scheduling/) | Maximum Profit In Job Scheduling | [c++](./leetcode/1235.maximum-profit-in-job-scheduling.cpp), [python3](./leetcode/1235.maximum-profit-in-job-scheduling.py) | Sorting | O\(NlogN\) | O\(N\) | - |
828833
| [Leetcode-2271](https://leetcode.com/problems/maximum-white-tiles-covered-by-a-carpet/) | Maximum White Tiles Covered By A Carpet | [c++](./leetcode/2271.maximum-white-tiles-covered-by-a-carpet.cpp), [python3](./leetcode/2271.maximum-white-tiles-covered-by-a-carpet.py) | Sorting | O\(NlogN\) | O\(1\) | - |
829834
| [Leetcode-56](https://leetcode.com/problems/merge-intervals/) | Merge Intervals | [c++](./leetcode/56.merge-intervals.cpp), [python3](./leetcode/56.merge-intervals.py) | Sorting | O\(NlogN\) | O\(1\) | - |
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Tag: Array, Math, Geometry, Sliding Window, Sorting
2+
// Time: O(NlogN)
3+
// Space: O(N)
4+
// Ref: -
5+
// Note: -
6+
7+
// You are given an array points, an integer angle, and your location, where location = [posx, posy] and points[i] = [xi, yi] both denote integral coordinates on the X-Y plane.
8+
// Initially, you are facing directly east from your position. You cannot move from your position, but you can rotate. In other words, posx and posy cannot be changed. Your field of view in degrees is represented by angle, determining how wide you can see from any given view direction. Let d be the amount in degrees that you rotate counterclockwise. Then, your field of view is the inclusive range of angles [d - angle/2, d + angle/2].
9+
//
10+
// Your browser does not support the video tag or this video format.
11+
//
12+
// You can see some set of points if, for each point, the angle formed by the point, your position, and the immediate east direction from your position is in your field of view.
13+
// There can be multiple points at one coordinate. There may be points at your location, and you can always see these points regardless of your rotation. Points do not obstruct your vision to other points.
14+
// Return the maximum number of points you can see.
15+
//  
16+
// Example 1:
17+
//
18+
//
19+
// Input: points = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1]
20+
// Output: 3
21+
// Explanation: The shaded region represents your field of view. All points can be made visible in your field of view, including [3,3] even though [2,2] is in front and in the same line of sight.
22+
//
23+
// Example 2:
24+
//
25+
// Input: points = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1]
26+
// Output: 4
27+
// Explanation: All points can be made visible in your field of view, including the one at your location.
28+
//
29+
// Example 3:
30+
//
31+
//
32+
// Input: points = [[1,0],[2,1]], angle = 13, location = [1,1]
33+
// Output: 1
34+
// Explanation: You can only see one of the two points, as shown above.
35+
//
36+
//  
37+
// Constraints:
38+
//
39+
// 1 <= points.length <= 105
40+
// points[i].length == 2
41+
// location.length == 2
42+
// 0 <= angle < 360
43+
// 0 <= posx, posy, xi, yi <= 100
44+
//
45+
//
46+
47+
class Solution {
48+
public:
49+
int visiblePoints(vector<vector<int>>& points, int angle, vector<int>& location) {
50+
int count = 0;
51+
vector<double> angles;
52+
53+
for (auto &p: points) {
54+
int x = p[0] - location[0];
55+
int y = p[1] - location[1];
56+
if (x == 0 && y == 0) {
57+
count += 1;
58+
} else {
59+
angles.push_back(atan2(y, x));
60+
}
61+
}
62+
63+
sort(angles.begin(), angles.end());
64+
int size = angles.size();
65+
for (int i = 0; i < size; i++) {
66+
angles.push_back(angles[i] + 2 * M_PI);
67+
}
68+
69+
double angle_radian = angle / 180.0 * M_PI;
70+
int res = 0;
71+
for (int i = 0; i < size; i++) {
72+
int j = upper_bound(angles.begin(), angles.end(), angles[i] + angle_radian) - angles.begin();
73+
res = max(res, j - i);
74+
}
75+
76+
return res + count;
77+
}
78+
};
79+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Tag: Array, Math, Geometry, Sliding Window, Sorting
2+
# Time: O(NlogN)
3+
# Space: O(N)
4+
# Ref: -
5+
# Note: -
6+
7+
# You are given an array points, an integer angle, and your location, where location = [posx, posy] and points[i] = [xi, yi] both denote integral coordinates on the X-Y plane.
8+
# Initially, you are facing directly east from your position. You cannot move from your position, but you can rotate. In other words, posx and posy cannot be changed. Your field of view in degrees is represented by angle, determining how wide you can see from any given view direction. Let d be the amount in degrees that you rotate counterclockwise. Then, your field of view is the inclusive range of angles [d - angle/2, d + angle/2].
9+
#
10+
# Your browser does not support the video tag or this video format.
11+
#
12+
# You can see some set of points if, for each point, the angle formed by the point, your position, and the immediate east direction from your position is in your field of view.
13+
# There can be multiple points at one coordinate. There may be points at your location, and you can always see these points regardless of your rotation. Points do not obstruct your vision to other points.
14+
# Return the maximum number of points you can see.
15+
#  
16+
# Example 1:
17+
#
18+
#
19+
# Input: points = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1]
20+
# Output: 3
21+
# Explanation: The shaded region represents your field of view. All points can be made visible in your field of view, including [3,3] even though [2,2] is in front and in the same line of sight.
22+
#
23+
# Example 2:
24+
#
25+
# Input: points = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1]
26+
# Output: 4
27+
# Explanation: All points can be made visible in your field of view, including the one at your location.
28+
#
29+
# Example 3:
30+
#
31+
#
32+
# Input: points = [[1,0],[2,1]], angle = 13, location = [1,1]
33+
# Output: 1
34+
# Explanation: You can only see one of the two points, as shown above.
35+
#
36+
#  
37+
# Constraints:
38+
#
39+
# 1 <= points.length <= 105
40+
# points[i].length == 2
41+
# location.length == 2
42+
# 0 <= angle < 360
43+
# 0 <= posx, posy, xi, yi <= 100
44+
#
45+
#
46+
47+
import math
48+
import bisect
49+
class Solution:
50+
def visiblePoints(self, points: List[List[int]], angle: int, location: List[int]) -> int:
51+
angles = []
52+
count = 0
53+
for p in points:
54+
x = p[0] - location[0]
55+
y = p[1] - location[1]
56+
if x == 0 and y == 0:
57+
count += 1
58+
else:
59+
angles.append(math.atan2(y, x))
60+
61+
angles.sort()
62+
size = len(angles)
63+
for i in range(size):
64+
angles.append(angles[i] + 2 * math.pi)
65+
66+
res = 0
67+
angle = angle / 180 * math.pi
68+
for i in range(size):
69+
j = bisect.bisect_right(angles, angles[i] + angle)
70+
res = max(res, j - i)
71+
72+
return res + count

0 commit comments

Comments
 (0)