Skip to content

Commit 525a9b8

Browse files
committed
0950 added.
1 parent f075ba5 commit 525a9b8

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
project(C)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
6+
add_executable(C main.cpp)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/// Source : https://leetcode.com/problems/reveal-cards-in-increasing-order/
2+
/// Author : liuyubobobo
3+
/// Time : 2018-12-01
4+
5+
#include <iostream>
6+
#include <vector>
7+
#include <deque>
8+
9+
using namespace std;
10+
11+
12+
/// Simulation with deque
13+
/// Time Complexity: O(nlogn)
14+
/// Space Complexity: O(n)
15+
class Solution {
16+
public:
17+
vector<int> deckRevealedIncreasing(vector<int>& deck) {
18+
19+
sort(deck.begin(), deck.end(), greater<int>());
20+
21+
deque<int> deque;
22+
deque.push_back(deck[0]);
23+
for(int i = 1; i < deck.size(); i ++){
24+
int back = deque.back();
25+
deque.pop_back();
26+
deque.push_front(back);
27+
deque.push_front(deck[i]);
28+
}
29+
30+
return vector<int>(deque.begin(), deque.end());
31+
}
32+
};
33+
34+
35+
void print_vec(const vector<int>& vec){
36+
for(int e: vec)
37+
cout << e << " ";
38+
cout << endl;
39+
}
40+
41+
int main() {
42+
43+
vector<int> deck1 = {17, 13, 11, 2, 3, 5, 7};
44+
print_vec(Solution().deckRevealedIncreasing(deck1));
45+
46+
return 0;
47+
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,4 +606,5 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
606606
| 947 | [Most Stones Removed with Same Row or Column](https://leetcode.com/problems/most-stones-removed-with-same-row-or-column/) | [solution](https://leetcode.com/problems/most-stones-removed-with-same-row-or-column/solution/) | [C++](0947-Most-Stones-Removed-with-Same-Row-or-Column/cpp-0947/) | | |
607607
| 948 | [Bag of Tokens](https://leetcode.com/problems/bag-of-tokens/) | [solution](https://leetcode.com/problems/bag-of-tokens/solution/) | [C++](0948-Bag-of-Tokens/cpp-0948/) | | |
608608
| 949 | [Largest Time for Given Digits](https://leetcode.com/problems/largest-time-for-given-digits/) | [solution](https://leetcode.com/problems/largest-time-for-given-digits/solution/) | [C++](0949-Largest-Time-for-Given-Digits/cpp-0949/) | | |
609+
| 950 | [Reveal Cards In Increasing Order](https://leetcode.com/problems/reveal-cards-in-increasing-order/) | [solution](https://leetcode.com/problems/reveal-cards-in-increasing-order/solution/) | [C++](0950-Reveal-Cards-In-Increasing-Order/cpp-0950/) | | |
609610
| | | | | | |

0 commit comments

Comments
 (0)