Untitled
unknown
plain_text
2 years ago
748 B
6
Indexable
class Solution {
public:
static bool cmp(vector<int>&a, vector<int>&b){
if(a[0]==b[0]) return a[1]>b[1];
return a[0]<b[0];
}
int numberOfPairs(vector<vector<int>>& pts) {
int cnt=0;
sort(pts.begin(),pts.end(),cmp);
int maxy=INT_MIN, minx=INT_MAX;
int n=pts.size();
for(int i=0;i<n;i++){
int x1=pts[i][0];
int y1=pts[i][1];
long long k=-10000000000;
for(int j=i+1;j<n;j++){
int x2=pts[j][0];
int y2=pts[j][1];
if(y2>y1) continue;
if(y2>k) {
cnt++;
k=y2;
}
}
}
return cnt;
}
};Editor is loading...
Leave a Comment