File tree 1 file changed +45
-0
lines changed
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ bool checkValidCuts(int n, vector<vector<int>>& rectangles) {
4
+ int s = rectangles.size();
5
+ vector<vector<int>> ver, hor;
6
+
7
+ // Store vertical and horizontal segment ranges
8
+ for (auto i : rectangles) {
9
+ ver.push_back({i[0], i[2]});
10
+ hor.push_back({i[1], i[3]});
11
+ }
12
+
13
+ // Sort vertical segments
14
+ sort(ver.begin(), ver.end());
15
+ int cnt = 1, mx = ver[0][1];
16
+
17
+ // Check for vertical cuts
18
+ for (int i = 1; i < s; i++) {
19
+ if (ver[i][0] < mx)
20
+ mx = max(mx, ver[i][1]);
21
+ else {
22
+ cnt++;
23
+ mx = ver[i][1];
24
+ }
25
+ if (cnt >= 3) return true;
26
+ }
27
+
28
+ // Sort horizontal segments
29
+ sort(hor.begin(), hor.end());
30
+ cnt = 1, mx = hor[0][1];
31
+
32
+ // Check for horizontal cuts
33
+ for (int i = 1; i < s; i++) {
34
+ if (hor[i][0] < mx)
35
+ mx = max(mx, hor[i][1]);
36
+ else {
37
+ cnt++;
38
+ mx = hor[i][1];
39
+ }
40
+ if (cnt >= 3) return true;
41
+ }
42
+
43
+ return false;
44
+ }
45
+ };
You can’t perform that action at this time.
0 commit comments