Skip to content

Commit 5d4644e

Browse files
committed
Time: 76 ms (87.89%), Space: 201.6 MB (80.49%) - LeetHub
1 parent 851cf53 commit 5d4644e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
public:
3+
bool checkValidCuts(int nn, vector<vector<int>>& rec) {
4+
5+
int n = rec.size();
6+
7+
auto check = [&] (auto& v) {
8+
sort(v.begin(), v.end(), [&](auto& a, auto& b) {
9+
return(a[0] < b[0] || (a[0] == b[0] && a[1] > b[1]));
10+
});
11+
int cnt = 0;
12+
int mx = 0;
13+
for (int i = 0; i < n; i++) {
14+
if (v[i][0] >= mx) cnt++;
15+
mx = max(mx, v[i][1]);
16+
}
17+
return cnt;
18+
};
19+
20+
for (int x = 0; x < 2; x++) {
21+
vector<array<int, 2>> temp;
22+
for (int i = 0; i < n; i++) {
23+
int a = rec[i][x], b = rec[i][x + 2];
24+
if (a > b) swap(a, b);
25+
temp.push_back({a, b});
26+
}
27+
if (check(temp) >= 3) return true;
28+
}
29+
return false;
30+
}
31+
};

0 commit comments

Comments
 (0)