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. JAVA环境安装配置

    dk1.6 64位是 Java 语言的软件开发工具包,主要用于移动设备.嵌入式设备上的java应用程序. jdk1.6 64位安装教程 jdk1.6 64位JDK的安装路径:D:\Program Fi ...

  2. 用js获取cookie

    //获取cookiefunction cookie_email(cookie_name){ var cookiestr = document.cookie; if (cookiestr.length ...

  3. hdu1269 Tarjan强连通分量 模板(转)

    #include<stdio.h> #include<iostream> #include<vector> using namespace std; ; vecto ...

  4. [docker]Kubernetes的yaml文件

    yaml是一种专门用来写配置的语言,简洁强大 它的规则: 1.大小写敏感 2.使用缩进表示层级关系,但不支持tab缩进,只支持空格 3.缩进的数量不重要但至少一个空格,只要相同层级使用相同数量的空格即 ...

  5. 编写高质量代码改善C#程序的157个建议——建议43:让接口中的泛型参数支持协变

    建议43:让接口中的泛型参数支持协变 除了上一建议中提到的使用泛型参数兼容接口不可变性外,还有一种办法是为接口中的泛型声明加上out关键字来支持协变,如下所示: interface ISalary&l ...

  6. poj3274 Gold Balanced Lineup(HASH)

    Description Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been abl ...

  7. 再解炸弹人——BFS

    原创 之前用了枚举法解炸弹人,题目详情请看我之前的博客:https://www.cnblogs.com/chiweiming/p/9295262.html 利用枚举法是无视地图布局的,枚举法直接全局搜 ...

  8. 积分之谜——第六届蓝桥杯C语言B组(国赛)第一题

    原创 标题:积分之迷 小明开了个网上商店,卖风铃.共有3个品牌:A,B,C. 为了促销,每件商品都会返固定的积分. 小明开业第一天收到了三笔订单: 第一笔:3个A + 7个B + 1个C,共返积分:3 ...

  9. Js 正则获取Html元素

    var html = $("#summaryTemplate").html(); var imageMath = /<img [^<,>]*(?=target-t ...

  10. Jquery Plugins Jquery Validate

      Jquery Validate 一.什么是Jquery Validate: jQuery Validate 插件为表单提供了强大的验证功能. 二.常用值: 1 required:true 必须输入 ...