Skip to content

Commit 23e56fa

Browse files
committed
Add solution #950
1 parent ce03cb3 commit 23e56fa

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,034 LeetCode solutions in JavaScript
1+
# 1,035 LeetCode solutions in JavaScript
22

33
[https://leetcode.com/](https://leetcode.com/)
44

@@ -759,6 +759,7 @@
759759
947|[Most Stones Removed with Same Row or Column](./solutions/0947-most-stones-removed-with-same-row-or-column.js)|Medium|
760760
948|[Bag of Tokens](./solutions/0948-bag-of-tokens.js)|Medium|
761761
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|
762763
966|[Vowel Spellchecker](./solutions/0966-vowel-spellchecker.js)|Medium|
763764
970|[Powerful Integers](./solutions/0970-powerful-integers.js)|Easy|
764765
976|[Largest Perimeter Triangle](./solutions/0976-largest-perimeter-triangle.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
};

0 commit comments

Comments
 (0)