nikunjsoni

899

Sep 5th, 2021
1,299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     string orderlyQueue(string S, int K) {
  4.         if (K > 1) {
  5.             sort(S.begin(), S.end());
  6.             return S;
  7.         }
  8.         string res = S;
  9.         for (int i = 1; i < S.length(); i++)
  10.             res = min(res, S.substr(i) + S.substr(0, i));
  11.         return res;
  12.     }
  13. };
Advertisement
Add Comment
Please, Sign In to add comment