aboutsummaryrefslogtreecommitdiff
path: root/other/orderly_queue.rs
diff options
context:
space:
mode:
Diffstat (limited to 'other/orderly_queue.rs')
-rw-r--r--other/orderly_queue.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/other/orderly_queue.rs b/other/orderly_queue.rs
new file mode 100644
index 0000000..0931d7b
--- /dev/null
+++ b/other/orderly_queue.rs
@@ -0,0 +1,22 @@
+struct Solution;
+
+impl Solution {
+ pub fn orderly_queue(s: String, k: i32) -> String {
+ if k == 1 {
+ let ss = s.chars().chain(s.chars()).collect::<Vec<_>>();
+ let mut v = ss.windows(s.len()).collect::<Vec<_>>();
+ v.sort();
+ v[0].iter().copied().collect()
+ } else {
+ let mut v = s.chars().collect::<Vec<_>>();
+ v.sort();
+ v.iter().collect()
+ }
+ }
+}
+
+fn main() {
+ let s = String::from("cba");
+ let k = 1;
+ print!("{}", Solution::orderly_queue(s, k));
+}