Skip to content

Latest commit

 

History

History
65 lines (45 loc) · 1.73 KB

_950. Reveal Cards In Increasing Order.md

File metadata and controls

65 lines (45 loc) · 1.73 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 12, 2024

Last updated : July 20, 2024


Related Topics : Array, Queue, Sorting, Simulation

Acceptance Rate : 83.06 %


Solutions

Python

class Solution:
    def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:
        deck.sort(reverse=True)
        print(deck)

        output = deque()

        for card in deck :
            if len(output) > 0 :
                output.appendleft(output.pop())
            
            output.appendleft(card)
        return list(output)
class Solution:
    def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:
        indices = deque(range(0, len(deck)))
        deck.sort()
        output = [0] * len(deck)

        deckSpot = 0
        while len(indices) > 1 :
            output[indices.popleft()] = deck[deckSpot]
            deckSpot += 1
            indices.append(indices.popleft())

        if indices :
            output[indices.pop()] = deck[deckSpot]
            
        return output