forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60066e2
commit 2f9fc1e
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/) | | | | ||
| | | | | | | |