Skip to content

Commit 3c924e1

Browse files
authored
Create 1899-merge-triplets-to-form-target-triplet.js
1 parent 2a93e19 commit 3c924e1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number[][]} triplets
3+
* @param {number[]} target
4+
* @return {boolean}
5+
*/
6+
const mergeTriplets = function (triplets, target) {
7+
let n = triplets.length
8+
const ans = Array(3).fill(0)
9+
const { max } = Math
10+
for (let i = 0; i < n; i++) {
11+
if (
12+
triplets[i][0] <= target[0] &&
13+
triplets[i][1] <= target[1] &&
14+
triplets[i][2] <= target[2]
15+
) {
16+
ans[0] = max(ans[0], triplets[i][0])
17+
ans[1] = max(ans[1], triplets[i][1])
18+
ans[2] = max(ans[2], triplets[i][2])
19+
}
20+
}
21+
return ans[0] == target[0] && ans[1] == target[1] && ans[2] == target[2]
22+
}

0 commit comments

Comments
 (0)