File tree 2 files changed +41
-1
lines changed
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,034 LeetCode solutions in JavaScript
1
+ # 1,035 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcode.com/ ] ( https://leetcode.com/ )
4
4
759
759
947|[ Most Stones Removed with Same Row or Column] ( ./solutions/0947-most-stones-removed-with-same-row-or-column.js ) |Medium|
760
760
948|[ Bag of Tokens] ( ./solutions/0948-bag-of-tokens.js ) |Medium|
761
761
949|[ Largest Time for Given Digits] ( ./solutions/0949-largest-time-for-given-digits.js ) |Medium|
762
+ 950|[ Reveal Cards In Increasing Order] ( ./solutions/0950-reveal-cards-in-increasing-order.js ) |Medium|
762
763
966|[ Vowel Spellchecker] ( ./solutions/0966-vowel-spellchecker.js ) |Medium|
763
764
970|[ Powerful Integers] ( ./solutions/0970-powerful-integers.js ) |Easy|
764
765
976|[ Largest Perimeter Triangle] ( ./solutions/0976-largest-perimeter-triangle.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 950. Reveal Cards In Increasing Order
3
+ * https://leetcode.com/problems/reveal-cards-in-increasing-order/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given an integer array deck. There is a deck of cards where every card has a
7
+ * unique integer. The integer on the ith card is deck[i].
8
+ *
9
+ * You can order the deck in any order you want. Initially, all the cards start face down
10
+ * (unrevealed) in one deck.
11
+ *
12
+ * You will do the following steps repeatedly until all cards are revealed:
13
+ * 1. Take the top card of the deck, reveal it, and take it out of the deck.
14
+ * 2. If there are still cards in the deck then put the next top card of the deck at the
15
+ * bottom of the deck.
16
+ * 3. If there are still unrevealed cards, go back to step 1. Otherwise, stop.
17
+ *
18
+ * Return an ordering of the deck that would reveal the cards in increasing order.
19
+ *
20
+ * Note that the first entry in the answer is considered to be the top of the deck.
21
+ */
22
+
23
+ /**
24
+ * @param {number[] } deck
25
+ * @return {number[] }
26
+ */
27
+ var deckRevealedIncreasing = function ( deck ) {
28
+ deck . sort ( ( a , b ) => b - a ) ;
29
+ const result = [ ] ;
30
+
31
+ for ( const card of deck ) {
32
+ if ( result . length ) {
33
+ result . unshift ( result . pop ( ) ) ;
34
+ }
35
+ result . unshift ( card ) ;
36
+ }
37
+
38
+ return result ;
39
+ } ;
You can’t perform that action at this time.
0 commit comments