Skip to content

Commit 52f4b09

Browse files
authored
Create 3025. Find the Number of Ways to Place People I (#875)
2 parents 386a680 + dc9e30b commit 52f4b09

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class compare
2+
{
3+
public:
4+
bool operator()(vector<int> &x,vector<int> &y)
5+
{
6+
if(x[0]==y[0]) return x[1]>y[1];
7+
return x[0]<y[0];
8+
}
9+
};
10+
class Solution {
11+
public:
12+
int numberOfPairs(vector<vector<int>>& points) {
13+
sort(points.begin(),points.end(),compare());
14+
int count=0;
15+
for(int i=0;i<points.size();i++)
16+
{
17+
for(int j=i+1;j<points.size();j++)
18+
{
19+
bool valid=true;
20+
if(points[i][0]<=points[j][0] && points[i][1]>=points[j][1])
21+
{
22+
valid=true;
23+
}
24+
else continue;
25+
for(int k=i+1;k<j;k++)
26+
{
27+
if(points[i][0]<=points[k][0] && points[k][0]<=points[j][0] && points[i][1]>=points[k][1] && points[k][1]>=points[j][1] )
28+
{
29+
valid=false;
30+
break;
31+
}
32+
}
33+
if(valid) count++;
34+
}
35+
}
36+
return count;
37+
}
38+
};

0 commit comments

Comments
 (0)