Skip to content

Commit

Permalink
0899 solved.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyubobobo committed Sep 2, 2018
1 parent 60066e2 commit 2f9fc1e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
7 changes: 7 additions & 0 deletions 0899-Orderly-Queue/cpp-0899/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.5)
project(cpp_0899)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(cpp_0899 ${SOURCE_FILES})
40 changes: 40 additions & 0 deletions 0899-Orderly-Queue/cpp-0899/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/// Source : https://leetcode.com/problems/orderly-queue/description/
/// Author : liuyubobobo
/// Time : 2018-09-02

#include <iostream>

using namespace std;


/// Mathematic
/// When K = 1, solve it brutely
/// When K = 2, we can get any permutation of the S
/// When K > 2, we can also get any permutation of the S
///
/// Time Complexity: O(n^2)
/// Space Complexity: O(n)
class Solution {
public:
string orderlyQueue(string S, int K) {

if(K == 1){
string ret = S;
for(int len = 1; len < S.size(); len ++){
string t_ret = S.substr(len) + S.substr(0, len);
if(t_ret < ret)
ret = t_ret;
}
return ret;
}

sort(S.begin(), S.end());
return S;
}
};


int main() {

return 0;
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,5 @@ email: [[email protected]](mailto:[email protected])
| 896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array/description/) | [solution](https://leetcode.com/problems/monotonic-array/solution/) | [C++](0896-Monotonic-Array/cpp-0896/) | | |
| 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree/description/) | [solution](https://leetcode.com/problems/increasing-order-search-tree/solution/) | [C++](0897-Increasing-Order-Search-Tree/cpp-0897/) | | |
| 898 | [Bitwise ORs of Subarrays](https://leetcode.com/problems/bitwise-ors-of-subarrays/description/) | [solution](https://leetcode.com/problems/bitwise-ors-of-subarrays/solution/) | [C++](0898-Bitwise-ORs-of-Subarrays/cpp-0898/) | | |
| | | | | | |
| 899 | [Orderly Queue](https://leetcode.com/problems/orderly-queue/description/) | [solution](https://leetcode.com/problems/orderly-queue/solution/) | [C++](0899-Orderly-Queue/cpp-0899/) | | |
| | | | | | |

0 comments on commit 2f9fc1e

Please sign in to comment.