1742. Orderly Queue
class Solution {
public:
/**
* @param S: a string
* @param K: int
* @return: the lexicographically smallest string
*/
string orderlyQueue(string &S, int K) {
// Write your code here.
if (K > 1) {
sort(S.begin(), S.end());
return S;
}
string res = S;
for (int i = 1; i < S.length(); i++)
res = min(res, S.substr(i) + S.substr(0, i));
return res;
}
};
Comments
Post a Comment