Skip to content

Commit b1cb0c0

Browse files
authored
Create 0950-reveal-cards-in-increasing-order.java
1 parent 7f79c9b commit b1cb0c0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: java/0950-reveal-cards-in-increasing-order.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int[] deckRevealedIncreasing(int[] deck) {
3+
Arrays.sort(deck);
4+
int[] res = new int[deck.length];
5+
ArrayDeque<Integer> q = new ArrayDeque<>();
6+
for (int i = 0; i < deck.length; i++) {
7+
q.addLast(i);
8+
}
9+
for (int n : deck) {
10+
int i = q.removeFirst();
11+
res[i] = n;
12+
if (!q.isEmpty()) {
13+
q.addLast(q.removeFirst());
14+
}
15+
}
16+
return res;
17+
}
18+
}

0 commit comments

Comments
 (0)