File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,763 LeetCode solutions in JavaScript
1
+ # 1,764 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1628
1628
2122|[ Recover the Original Array] ( ./solutions/2122-recover-the-original-array.js ) |Hard|
1629
1629
2124|[ Check if All A's Appears Before All B's] ( ./solutions/2124-check-if-all-as-appears-before-all-bs.js ) |Easy|
1630
1630
2125|[ Number of Laser Beams in a Bank] ( ./solutions/2125-number-of-laser-beams-in-a-bank.js ) |Medium|
1631
+ 2126|[ Destroying Asteroids] ( ./solutions/2126-destroying-asteroids.js ) |Medium|
1631
1632
2127|[ Maximum Employees to Be Invited to a Meeting] ( ./solutions/2127-maximum-employees-to-be-invited-to-a-meeting.js ) |Hard|
1632
1633
2129|[ Capitalize the Title] ( ./solutions/2129-capitalize-the-title.js ) |Easy|
1633
1634
2130|[ Maximum Twin Sum of a Linked List] ( ./solutions/2130-maximum-twin-sum-of-a-linked-list.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2126. Destroying Asteroids
3
+ * https://leetcode.com/problems/destroying-asteroids/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given an integer mass, which represents the original mass of a planet. You are further
7
+ * given an integer array asteroids, where asteroids[i] is the mass of the ith asteroid.
8
+ *
9
+ * You can arrange for the planet to collide with the asteroids in any arbitrary order. If the mass
10
+ * of the planet is greater than or equal to the mass of the asteroid, the asteroid is destroyed
11
+ * and the planet gains the mass of the asteroid. Otherwise, the planet is destroyed.
12
+ *
13
+ * Return true if all asteroids can be destroyed. Otherwise, return false.
14
+ */
15
+
16
+ /**
17
+ * @param {number } mass
18
+ * @param {number[] } asteroids
19
+ * @return {boolean }
20
+ */
21
+ var asteroidsDestroyed = function ( mass , asteroids ) {
22
+ asteroids . sort ( ( a , b ) => a - b ) ;
23
+
24
+ let planetMass = BigInt ( mass ) ;
25
+ for ( const asteroid of asteroids ) {
26
+ if ( planetMass < BigInt ( asteroid ) ) return false ;
27
+ planetMass += BigInt ( asteroid ) ;
28
+ }
29
+
30
+ return true ;
31
+ } ;
You can’t perform that action at this time.
0 commit comments