All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 12, 2024
Last updated : July 20, 2024
Related Topics : Array, Queue, Sorting, Simulation
Acceptance Rate : 83.06 %
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