[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/pythonpeixun/LeetCode-Solutions/master/Python/orderly-queue.py [Back]  [Original]

# Time:  O(n^2)
# Space: O(n)

class Solution(object):
    def orderlyQueue(self, S, K):
        """
        :type S: str
        :type K: int
        :rtype: str
        """
        if K == 1:
            return min(S[i:] + S[:i] for i in xrange(len(S)))
        return "".join(sorted(S))


Web Proxy Viewer  |  New URL  |  Original Page