Leetcode - Valid Sudoku
Leetcode - Lonely Pixel I

Leetcode - Reveal Cards In Increasing Order

violet posted @ Apr 18, 2020 06:32:54 AM in 算法 with tags Algorithm Golang array Simulation , 305 阅读

https://leetcode.com/problems/reveal-cards-in-increasing-order/

In a deck of cards, every card has a unique integer.  You can order the deck in any order you want.

Initially, all the cards start face down (unrevealed) in one deck.

Now, you do the following steps repeatedly, until all cards are revealed:

  1. Take the top card of the deck, reveal it, and take it out of the deck.
  2. If there are still cards in the deck, put the next top card of the deck at the bottom of the deck.
  3. If there are still unrevealed cards, go back to step 1.  Otherwise, stop.

Return an ordering of the deck that would reveal the cards in increasing order.

The first entry in the answer is considered to be the top of the deck.

 

Totally shitty question.

func deckRevealedIncreasing(deck []int) []int {
    sort.Ints(deck)
    queue := []int{}
    for i := 0; i < len(deck); i++ {
        queue = append(queue, i)
    }
    result := make([]int, len(deck))
    for i := 0; i < len(deck); i++ {
        index := queue[0]
        result[index] = deck[i]
        queue = queue[1:]
        if len(queue) > 0 {
            queue = append(queue, queue[0])
            queue = queue[1:]
        }
    }
    return result
}
NCERT Urdu Sample Pa 说:
Sep 26, 2022 03:12:21 PM

Urdu Language was constitutionally given national status. Now Urdu is our national language, but provincialism and ethnicism are out to kill the national language. Like past heritage and traditions, language plays a very important role in national awakening and national integration. Urdu is ideally suited for expression and instructions in art, science, and commerce up to the university level.NCERT Urdu Sample Paper Class 9 Urdu Language was constitutionally given national status. Now Urdu is our national language, but provincialism and ethnicism are out to kill the national language. Like past heritage and traditions.

Delhi Escort 说:
Dec 28, 2022 10:16:17 PM

The great thing about this blog is the conversational tone and the real person behind the brand. I found this post I liked everything in this post this post is beneficial for me.
<a href="https://www.delhihiprofileescorts.com/">Escort in Delhi</a>

Delhi Escort Service 说:
Dec 28, 2022 10:16:54 PM

This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up.

Escort Service in De 说:
Dec 28, 2022 10:17:29 PM

This is a great idea that opens the variety of options available for you to make the new future I really love to read more articles on this kind of event which really helps people.

Mumbai Escort 说:
Dec 28, 2022 10:17:59 PM

I see your post and reed. This is good for me this is a good post you give a piece of great information and helpful thanks for sharing this side.

Netaji Subhash Place 说:
Dec 23, 2023 06:01:34 PM

I uncommonly esteem your committed capacities as the post you circulated have a few unprecedented information which is exceptionally worthwhile for me.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter