Skip to content

Commit 55339ff

Browse files
committed
2126. Destroying Asteroids: RETRY
1 parent 527c32c commit 55339ff

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,3 +1605,4 @@ mod s2121_intervals_between_identical_elements;
16051605
mod s2122_recover_the_original_array;
16061606
mod s2124_check_if_all_as_appears_before_all_bs;
16071607
mod s2125_number_of_laser_beams_in_a_bank;
1608+
mod s2126_destroying_asteroids;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* [2126] Destroying Asteroids
3+
*
4+
* You are given an integer mass, which represents the original mass of a planet. You are further given an integer array asteroids, where asteroids[i] is the mass of the i^th asteroid.
5+
* You can arrange for the planet to collide with the asteroids in any arbitrary order. If the mass of the planet is greater than or equal to the mass of the asteroid, the asteroid is destroyed and the planet gains the mass of the asteroid. Otherwise, the planet is destroyed.
6+
* Return true if all asteroids can be destroyed. Otherwise, return false.
7+
*
8+
* Example 1:
9+
*
10+
* Input: mass = 10, asteroids = [3,9,19,5,21]
11+
* Output: true
12+
* Explanation: One way to order the asteroids is [9,19,5,3,21]:
13+
* - The planet collides with the asteroid with a mass of 9. New planet mass: 10 + 9 = 19
14+
* - The planet collides with the asteroid with a mass of 19. New planet mass: 19 + 19 = 38
15+
* - The planet collides with the asteroid with a mass of 5. New planet mass: 38 + 5 = 43
16+
* - The planet collides with the asteroid with a mass of 3. New planet mass: 43 + 3 = 46
17+
* - The planet collides with the asteroid with a mass of 21. New planet mass: 46 + 21 = 67
18+
* All asteroids are destroyed.
19+
*
20+
* Example 2:
21+
*
22+
* Input: mass = 5, asteroids = [4,9,23,4]
23+
* Output: false
24+
* Explanation:
25+
* The planet cannot ever gain enough mass to destroy the asteroid with a mass of 23.
26+
* After the planet destroys the other asteroids, it will have a mass of 5 + 4 + 9 + 4 = 22.
27+
* This is less than 23, so a collision would not destroy the last asteroid.
28+
*
29+
* Constraints:
30+
*
31+
* 1 <= mass <= 10^5
32+
* 1 <= asteroids.length <= 10^5
33+
* 1 <= asteroids[i] <= 10^5
34+
*
35+
*/
36+
pub struct Solution {}
37+
38+
// problem: https://leetcode.com/problems/destroying-asteroids/
39+
// discuss: https://leetcode.com/problems/destroying-asteroids/discuss/?currentPage=1&orderBy=most_votes&query=
40+
41+
// submission codes start here
42+
43+
impl Solution {
44+
pub fn asteroids_destroyed(mass: i32, asteroids: Vec<i32>) -> bool {
45+
false
46+
}
47+
}
48+
49+
// submission codes end
50+
51+
#[cfg(test)]
52+
mod tests {
53+
use super::*;
54+
55+
#[test]
56+
#[ignore]
57+
fn test_2126_example_1() {
58+
let mass = 10;
59+
let asteroids = vec![3, 9, 19, 5, 21];
60+
61+
let result = true;
62+
63+
assert_eq!(Solution::asteroids_destroyed(mass, asteroids), result);
64+
}
65+
66+
#[test]
67+
#[ignore]
68+
fn test_2126_example_2() {
69+
let mass = 5;
70+
let asteroids = vec![4, 9, 23, 4];
71+
72+
let result = false;
73+
74+
assert_eq!(Solution::asteroids_destroyed(mass, asteroids), result);
75+
}
76+
}

0 commit comments

Comments
 (0)