We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b7c6681 commit 158283dCopy full SHA for 158283d
899-orderly-queue.js
@@ -0,0 +1,21 @@
1
+/**
2
+ * @param {string} S
3
+ * @param {number} K
4
+ * @return {string}
5
+ */
6
+const orderlyQueue = function (S, K) {
7
+ if (K === 0) return S
8
+ else if (K > 1) return S.split('').sort().join('')
9
+ let result = 0,
10
+ L = S.length
11
+ for (let i = 1; i < L; i++) {
12
+ for (let j = 0; j < L; j++) {
13
+ let d = S.charCodeAt((result + j) % L) - S.charCodeAt((i + j) % L)
14
+ if (d !== 0) {
15
+ if (d > 0) result = i
16
+ break
17
+ }
18
19
20
+ return S.slice(result) + S.slice(0, result)
21
+}
0 commit comments