735. Asteroid Collision Medium

@problem@discussion
#Array#Stack



1/**
2 * [735] Asteroid Collision
3 *
4 * We are given an array asteroids of integers representing asteroids in a row.
5 * For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.
6 * Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.
7 *  
8 * Example 1:
9 * 
10 * Input: asteroids = [5,10,-5]
11 * Output: [5,10]
12 * Explanation: The 10 and -5 collide resulting in 10. The 5 and 10 never collide.
13 * 
14 * Example 2:
15 * 
16 * Input: asteroids = [8,-8]
17 * Output: []
18 * Explanation: The 8 and -8 collide exploding each other.
19 * 
20 * Example 3:
21 * 
22 * Input: asteroids = [10,2,-5]
23 * Output: [10]
24 * Explanation: The 2 and -5 collide resulting in -5. The 10 and -5 collide resulting in 10.
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	2 <= asteroids.length <= 10^4
30 * 	-1000 <= asteroids[i] <= 1000
31 * 	asteroids[i] != 0
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/asteroid-collision/
37// discuss: https://leetcode.com/problems/asteroid-collision/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn asteroid_collision(asteroids: Vec<i32>) -> Vec<i32> {
43        vec![]
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_735() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.