Skip to content

Commit 448d256

Browse files
authored
Create merge-triplets-to-form-target-triplet.cpp
1 parent 6cd20b6 commit 448d256

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
bool mergeTriplets(vector<vector<int>>& triplets, vector<int>& target) {
7+
vector<int> result(3);
8+
for (const auto& t : triplets) {
9+
if (t[0] <= target[0] && t[1] <= target[1] && t[2] <= target[2]) {
10+
result = {max(result[0], t[0]), max(result[1], t[1]), max(result[2], t[2])};
11+
}
12+
}
13+
return result == target;
14+
}
15+
};

0 commit comments

Comments
 (0)