# 1899. Merge Triplets to Form Target Triplet ###### tags: `Leetcode` `Medium` `Greedy` Link: https://leetcode.com/problems/merge-triplets-to-form-target-triplet/description/ ## 思路 有任何一个数大于target里面对应的数的triplet肯定要被舍弃 对于剩下的triplets 每一位取最大值 如果最后的结果和target相同就返回true ## Code ```java= class Solution { public boolean mergeTriplets(int[][] triplets, int[] target) { int[] res = new int[3]; for(int[] triplet:triplets){ if(triplet[0]<=target[0] && triplet[1]<=target[1] && triplet[2]<=target[2]){ res = new int[]{Math.max(triplet[0], res[0]), Math.max(triplet[1], res[1]), Math.max(triplet[2], res[2])}; } } return Arrays.equals(res, target); } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up