Skip to content

Commit e779a35

Browse files
committed
Runtime: 38 ms (Top 82.70%) | Memory: 13.7 MB (Top 45.37%)
1 parent 9bb9366 commit e779a35

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
// Runtime: 38 ms (Top 82.70%) | Memory: 13.7 MB (Top 45.37%)
12
class Solution {
23
public:
3-
4-
//DP solution
4+
5+
//DP solution
56
//TC-O(N*N)
67
//SC- ~ O(N*N)
7-
//Custom Sort
8+
//Custom Sort
89
bool static cmp(vector<int> p1,vector<int> p2){
910
if(p1[0]==p2[0])
1011
return p1[1]<p2[1];
1112
return p1[0]<p2[0];
1213
}
13-
14-
//Slope Calculating
14+
15+
//Slope Calculating
1516
float calcSlope(int x1,int y1,int x2,int y2){
16-
return (y2-y1)/(float)(x2-x1);
17+
return (y2-y1)/(float)(x2-x1);
1718
}
1819
int maxPoints(vector<vector<int>>& points) {
1920
if(points.size()==2 || points.size()==1)
2021
return points.size();
21-
22+
2223
sort(points.begin(),points.end(),cmp);
2324
int ans=1;
24-
//How much points having same slope at current index
25+
//How much points having same slope at current index
2526
vector<unordered_map<float,int>> dp(points.size()+1);
2627
for(int i=1;i<points.size();i++){
2728
for(int j=0;j<i;j++){
@@ -34,9 +35,9 @@ class Solution {
3435
}
3536
}
3637
}
37-
//return ans
38-
38+
//return ans
39+
3940
return ans+1;
40-
41+
4142
}
42-
};
43+
};

0 commit comments

Comments
 (0)