Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cb78d3d

Browse files
committed
docs: add 1899. Merge Triplets to Form Target Triplet
1 parent a900e6d commit cb78d3d

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

‎src/medium/readme.md‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,38 @@ Put the code below in main.rs and run `cargo run`
22562256
println!("result: {:?}", result);
22572257
```
22582258

2259+
# 846. Hand of Straights
2260+
2261+
## Description
2262+
2263+
Alice has a `hand` of cards, given as an array of integers.
2264+
2265+
Now she wants to rearrange the cards into groups so that each group is size `W`, and consists of `W` consecutive cards.
2266+
2267+
Return `true` if and only if she can.
2268+
2269+
Note: This question is the same as 1296: https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/
2270+
2271+
## Examples
2272+
2273+
```text
2274+
Input: hand = [1,2,3,6,2,3,4,7,8], W = 3
2275+
Output: true
2276+
2277+
Explanation: Alice's hand can be rearranged as [1,2,3],[2,3,4],[6,7,8].
2278+
```
2279+
2280+
## How to Run in main.rs
2281+
2282+
Put the code below in main.rs and run `cargo run`
2283+
2284+
```rust
2285+
let hand = vec![1, 2, 3, 6, 2, 3, 4, 7, 8];
2286+
let w = 3;
2287+
let result = leetcode::medium::hand_of_straights::is_n_straight_hand(hand, w);
2288+
println!("result: {}", result);
2289+
```
2290+
22592291
# 853. Car Fleet
22602292

22612293
## Description
@@ -2503,3 +2535,51 @@ Put the code below in main.rs and run `cargo run`
25032535
println!("result: {}", result);
25042536
```
25052537

2538+
2539+
# 1899. Merge Triplets to Form Target Triplet
2540+
2541+
## Description
2542+
2543+
A triplet is an array of three integers. You are given a 2D integer array `triplets`, where `triplets[i] = [ai, bi, ci]` describes the ith triplet. You are also given an integer array` target = [x, y, z]` that describes the triplet you want to obtain.
2544+
2545+
To obtain target, you may apply the following operation on triplets any number of times (possibly zero):
2546+
2547+
- Choose two indices (0-indexed) `i `and `j (i != j) `and update `triplets[j]` to become `[max(ai, aj), max(bi, bj), max(ci, cj)]`.
2548+
- For example, if `triplets[i] = [2, 5, 3]` and `triplets[j] = [1, 7, 5]`, `triplets[j] `will be updated to `[max(2, 1), max(5, 7), max(3, 5)] = [2, 7, 5]`.
2549+
Return true if it is possible to obtain the target triplet [x, y, z] as an element of triplets, or false otherwise.
2550+
2551+
## Examples
2552+
2553+
```text
2554+
Example 1:
2555+
2556+
Input: triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]
2557+
Output: true
2558+
Explanation: Perform the following operations:
2559+
- Choose the first and last triplets [[2,5,3],[1,8,4],[1,7,5]]. Update the last triplet to be [max(2,1), max(5,7), max(3,5)] = [2,7,5]. triplets = [[2,5,3],[1,8,4],[2,7,5]]
2560+
The target triplet [2,7,5] is now an element of triplets.
2561+
Example 2:
2562+
2563+
Input: triplets = [[3,4,5],[4,5,6]], target = [3,2,5]
2564+
Output: false
2565+
Explanation: It is impossible to have [3,2,5] as an element because there is no 2 in any of the triplets.
2566+
Example 3:
2567+
2568+
Input: triplets = [[2,5,3],[2,3,4],[1,2,5],[5,2,3]], target = [5,5,5]
2569+
Output: true
2570+
Explanation: Perform the following operations:
2571+
- Choose the first and third triplets [[2,5,3],[2,3,4],[1,2,5],[5,2,3]]. Update the third triplet to be [max(2,1), max(5,2), max(3,5)] = [2,5,5]. triplets = [[2,5,3],[2,3,4],[2,5,5],[5,2,3]].
2572+
- Choose the third and fourth triplets [[2,5,3],[2,3,4],[2,5,5],[5,2,3]]. Update the fourth triplet to be [max(2,5), max(5,2), max(5,3)] = [5,5,5]. triplets = [[2,5,3],[2,3,4],[2,5,5],[5,5,5]].
2573+
The target triplet [5,5,5] is now an element of triplets.
2574+
```
2575+
2576+
## How to Run in main.rs
2577+
2578+
Put the code below in main.rs and run `cargo run`
2579+
2580+
```rust
2581+
let triplets = vec![vec![2, 5, 3], vec![1, 8, 4], vec![1, 7, 5]];
2582+
let target = vec![2, 7, 5];
2583+
let result = leetcode::medium::merge_triplets_to_form_target_triplet::merge_triplets(triplets, target);
2584+
println!("result: {}", result);
2585+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /