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.

Example 1:

Input: [17,13,11,2,3,5,7]
Output: [2,13,3,11,5,17,7]
Explanation:
We get the deck in the order [17,13,11,2,3,5,7] (this order doesn't matter), and reorder it.
After reordering, the deck starts as [2,13,3,11,5,17,7], where 2 is the top of the deck.
We reveal 2, and move 13 to the bottom. The deck is now [3,11,5,17,7,13].
We reveal 3, and move 11 to the bottom. The deck is now [5,17,7,13,11].
We reveal 5, and move 17 to the bottom. The deck is now [7,13,11,17].
We reveal 7, and move 13 to the bottom. The deck is now [11,17,13].
We reveal 11, and move 17 to the bottom. The deck is now [13,17].
We reveal 13, and move 17 to the bottom. The deck is now [17].
We reveal 17.
Since all the cards revealed are in increasing order, the answer is correct.

Note:

  1. 1 <= A.length <= 1000
  2. 1 <= A[i] <= 10^6
  3. A[i] != A[j] for all i != j

倒过来看就能找到规律

class Solution {
public:
vector<int> deckRevealedIncreasing(vector<int>& deck) {
int s = deck.size();
sort(deck.begin(),deck.end());
if(s==){
return deck;
}
if(s==){
return deck;
}
vector<int> result;
result.push_back(deck[s-]);
result.push_back(deck[s-]);
for(int i=s-;i>=;i--){ int len = result.size();
int last= result[len-];
result.insert(result.begin(),last); result.pop_back();
result.insert(result.begin(),deck[i]); }
return result;
}
};

113th LeetCode Weekly Contest Reveal Cards In Increasing Order的更多相关文章

  1. 【LeetCode】950. Reveal Cards In Increasing Order 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 模拟 日期 题目地址:https://leetcod ...

  2. [Swift]LeetCode950. 按递增顺序显示卡牌 | 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. ...

  3. Reveal Cards In Increasing Order LT950

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

  4. [Solution] 950. Reveal Cards In Increasing Order

    Difficulty: Medium Problem In a deck of cards, every card has a unique integer. You can order the de ...

  5. 【leedcode】950. 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 ...

  6. 113th LeetCode Weekly Contest Flip Equivalent Binary Trees

    For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left a ...

  7. 113th LeetCode Weekly Contest Largest Time for Given Digits

    Given an array of 4 digits, return the largest 24 hour time that can be made. The smallest 24 hour t ...

  8. 揭示牌面使之升序 Reveal Cards In Increasing Order

    2019-03-27 14:10:37 问题描述: 问题求解: 模拟题.考虑角度是从结果来进行反推. input - [2,3,5,7,11,13,17] (just sort the input t ...

  9. Leetcode950. Reveal Cards In Increasing Order按递增顺序显示卡牌

    牌组中的每张卡牌都对应有一个唯一的整数.你可以按你想要的顺序对这套卡片进行排序. 最初,这些卡牌在牌组里是正面朝下的(即,未显示状态). 现在,重复执行以下步骤,直到显示所有卡牌为止: 从牌组顶部抽一 ...

随机推荐

  1. 面试题:JVM类加载机制详解(一)JVM类加载过程 背1

    首先Throws(抛出)几个自己学习过程中一直疑惑的问题: 1.什么是类加载?什么时候进行类加载? 2.什么是类初始化?什么时候进行类初始化? 3.什么时候会为变量分配内存? 4.什么时候会为变量赋默 ...

  2. Entity Framework在不同数据库下的配置

    http://blog.csdn.net/weiky626/article/details/17068593 http://blog.csdn.net/niewq/article/details/41 ...

  3. MagicNotes:如何迈向工作的坦途

    MagicNotes,思绪随风飞扬,不抓住写下来明天就会忘记了. 昨晚在知乎上偶尔看到 @雨农 的关于“为什么我那么努力,吃了那么多苦,也没见那么优秀?”的一个回复,心里有所触动. 本人专科毕业3-4 ...

  4. Entity Framework Tutorial Basics(40):Validate Entity

    Validate Entity You can write custom server side validation for any entity. To accomplish this, over ...

  5. hdu 2211 杀人游戏

    设f(N,K)返回最后取出的编号 那么f(n,k)进行第一次选后,剩下n-n/k个人,这剩下的人里最后被取出的编号为f(n-n/k,k)记为x 那么它在前一次队列里的编号则是(x-1)/(k-1)+x ...

  6. Edge 自动给数字加下划线的问题

    <meta name="format-detection" content="telephone=no,email=no,address=no">

  7. 无限级分类及生成json数据

    第一步,先去数据库查询类别数据,然后交给生成json数据的函数处理,代码如下: /*生成类别JSON数据*/ public function wirteJson(){ $dataInfo = \thi ...

  8. Fiddler 教程之:Fiddler捕获会话

    1 Fiddler的工作原理 Fiddler 是以代理web服务器的形式工作的,它使用代理地址:127.0.0.1,端口:8888.当Fiddler退出的时候它会自动注销,这样就不会影响别的程序.不过 ...

  9. WordPaster2-正式包布署说明

    1.1. 多平台布署说明 提供信息如下: 1.多平台控件包(根据购买版本提供) 2.控件信息 3.配置方法   WordPaster(x86)Clsid信息 ClsidParser F4B7C0FD- ...

  10. 状态压缩-----HDU1074 Doing Homework

    HDU1074 Doing Homework 题意:给了n个家庭作业,然后给了每个家庭作业的完成期限和花费的实践,如果完成时间超过了期限,那么就要扣除分数,然后让你找出一个最优方案使扣除的分数最少,当 ...