#include <stdbool.h>
bool mergeTriplets(int **triplets, int tripletsSize, int *tripletsColSize,
int *target, int targetSize) {
(void)tripletsColSize; // always 3
(void)targetSize; // always 3
bool found[3] = {false, false, false};
for (int k = 0; k < tripletsSize; k++) {
int *t = triplets[k];
if (t[0] > target[0] || t[1] > target[1] || t[2] > target[2])
continue;
for (int i = 0; i < 3; i++)
if (t[i] == target[i])
found[i] = true;
}
return found[0] && found[1] && found[2];
}
#include <vector>
using namespace std;
class Solution {
public:
bool mergeTriplets(vector<vector<int>> &triplets, vector<int> &target) {
bool found[3] = {false, false, false};
for (auto &t : triplets) {
if (t[0] > target[0] || t[1] > target[1] || t[2] > target[2])
continue;
for (int i = 0; i < 3; i++)
if (t[i] == target[i])
found[i] = true;
}
return found[0] && found[1] && found[2];
}
};
package greedy
func mergeTriplets(triplets [][]int, target []int) bool {
var found [3]bool
for _, t := range triplets {
if t[0] > target[0] || t[1] > target[1] || t[2] > target[2] {
continue
}
for i := 0; i < 3; i++ {
if t[i] == target[i] {
found[i] = true
}
}
}
return found[0] && found[1] && found[2]
}
class Solution {
public boolean mergeTriplets(int[][] triplets, int[] target) {
boolean[] found = new boolean[3];
for (int[] t : triplets) {
if (t[0] > target[0] || t[1] > target[1] || t[2] > target[2])
continue;
for (int i = 0; i < 3; i++)
if (t[i] == target[i])
found[i] = true;
}
return found[0] && found[1] && found[2];
}
}
/**
* @param {number[][]} triplets
* @param {number[]} target
* @return {boolean}
*/
var mergeTriplets = function (triplets, target) {
const found = [false, false, false];
for (const t of triplets) {
if (t[0] > target[0] || t[1] > target[1] || t[2] > target[2]) continue;
for (let i = 0; i < 3; i++) if (t[i] === target[i]) found[i] = true;
}
return found[0] && found[1] && found[2];
};
from typing import List
class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
found = [False, False, False]
for t in triplets:
if t[0] > target[0] or t[1] > target[1] or t[2] > target[2]:
continue
for i in range(3):
if t[i] == target[i]:
found[i] = True
return all(found)
impl Solution {
pub fn merge_triplets(triplets: Vec<Vec<i32>>, target: Vec<i32>) -> bool {
let mut found = [false; 3];
for t in &triplets {
if t[0] > target[0] || t[1] > target[1] || t[2] > target[2] {
continue;
}
for i in 0..3 {
if t[i] == target[i] {
found[i] = true;
}
}
}
found.iter().all(|&f| f)
}
}