Skip to content

Commit 40e8785

Browse files
committed
update 950 java
1 parent b509477 commit 40e8785

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

leetcode_java/src/main/java/LeetCodeJava/Array/RevealCardsInIncreasingOrder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public class RevealCardsInIncreasingOrder {
6060
//
6161
// }
6262

63+
// V0-1
64+
// IDEA : QUEUE
65+
// https://www.youtube.com/watch?v=i2QrUdwWlak
66+
6367
// V1-1
6468
// IDEA : Simulation with Queue
6569
// https://leetcode.com/problems/reveal-cards-in-increasing-order/editorial/

leetcode_java/src/main/java/dev/workspace5.java

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,9 +3205,70 @@ public String findReplaceString(String s, int[] indices, String[] sources, Strin
32053205

32063206
// LC 950
32073207
// https://leetcode.com/problems/reveal-cards-in-increasing-order/
3208-
// 5.14 pm - 5.30 pm
3208+
// 5.54 pm - 6.15 pm
3209+
// idea : queue simulation
3210+
/**
3211+
*
3212+
* You will do the following steps repeatedly until all cards are revealed:
3213+
*
3214+
* - Take the top card of the deck, reveal it, and take it out of the deck.
3215+
*
3216+
* - If there are still cards in the deck then put the next top card of the
3217+
* deck at the bottom of the deck.
3218+
*
3219+
* - If there are still unrevealed cards, go back to step 1. Otherwise, stop.
3220+
*
3221+
*/
3222+
/**
3223+
* Idea 1)
3224+
*
3225+
* deck = [17,13,11,2,3,5,7]
3226+
*
3227+
* step 1) sort
3228+
* -> [2,3,5,7,11,13,17]
3229+
*
3230+
* step 2)
3231+
* queue simulation flip op
3232+
* -> [3,5,7,11,13,17], queue = [2]
3233+
*
3234+
*
3235+
* -> [5,7,11,13,17], queue = [2, 3]
3236+
*
3237+
* -> [7,11,13,17], queue = [5, 2, 3]
3238+
*
3239+
* -> [11,13,17], queue = [5, 2, ,7,3]
3240+
*
3241+
* -> [13,17], queue = [5, 2, 11, ,7,3]
3242+
*
3243+
*
3244+
*
3245+
*
3246+
*/
32093247
public int[] deckRevealedIncreasing(int[] deck) {
3210-
return null;
3248+
//List<Integer> list = new ArrayList<>();
3249+
if (deck.length == 0){
3250+
return null; // ?
3251+
}
3252+
if (deck.length == 1){
3253+
return deck; // ?
3254+
}
3255+
3256+
// sorting
3257+
Arrays.sort(deck);
3258+
3259+
// init
3260+
Queue<Integer> queue = new LinkedList<>();
3261+
List<Integer> idxList = new ArrayList<>();
3262+
3263+
3264+
int[] res = new int[deck.length];
3265+
int j = 0;
3266+
while(!queue.isEmpty()){
3267+
res[j] = queue.poll();
3268+
j += 1;
3269+
}
3270+
3271+
return res;
32113272
}
32123273

32133274

0 commit comments

Comments
 (0)