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. c语言学习笔记 多级else if 和switch case有什么区别

    ; ) { dosth(); } ) { dosth2(); } else if(opion==) { dosth3(); } else dosth4(); 如果给option的一个值是2的话,那么程 ...

  2. Windows Chocolatey

    一.简介 Chocolatey是Windows下包管理工具,可以使用 Chocolatey 来安装应用程序.   二.安装 1)在线安装:参见 主页 官网:https://chocolatey.org ...

  3. NEERC17 J Journey from Petersburg to Moscow

    CF上可以提交.   链接 依然是很妙的解法. 我们可以枚举每一个出现过的边权$L$,然后把所有边的边权减掉这个$L$,如果小于$L$就变为$0$,然后跑一遍最短路然后加上$k * L$更新答案即可. ...

  4. python3--装饰器高级学习版

    __author__ = "Aaron Fan"import time #导入time模块user,passwd = 'alex','abc123' #用户名密码def auth( ...

  5. javascript总结4:javascript常见变量

    1 javascript变量 定义:变量在计算机中,是用于存储信息的"容器". 2  使用方法: 2-1 定义变量: var n1; 2-2 变量赋值: var n2=23.45; ...

  6. Chrome浏览器控件安装方法

    说明:只需要安装up6.exe即可,up6.exe为插件集成安装包. 1.以管理员身份运行up6.exe.up6.exe中已经集成Chrome插件.  

  7. springMVC传对象参数

    springController: [java] view plaincopy @Controller @RequestMapping("/user") public UserCo ...

  8. jQuery高级

    一.动画效果 常用的几种效果都是没有easing参数的,也即动画只能swing.$(selector).animate(styles,speed,easing,callback)中是有easing参数 ...

  9. HackOne

    使用 weight 属性实现视图的居中显示 一.在开发中有时候会遇到将一个控件在父控件居中显示.但是如果你直接用margin_*来进行限制的话就可能造成对于不同的型号的手机又不同显示的格式. 所以就可 ...

  10. C# Socket 发送&接收&返回

    因为工作比较忙,好久没有写过博客了,最近因项目需求,需要用到Socket来进行通信,简单写了几个例子,记录一下,代码很简单,无非就是接收与发送,以及接收到数据后返回一个自定义信息,也可以说是发送. 先 ...