LintCode:Left Pad

LintCode:Left Pad这里写链接内容

class StringUtils:
    # @param {string} originalStr the string we want to append to
    # @param {int} size the target length of the string
    # @param {string} padChar the character to pad to the left side of the string
    # @return {string} a string
    @classmethod
    def leftPad(self, originalStr, size, padChar=' '):
        # Write your code here
        if len(originalStr) >= size:
            return originalStr
        ans = padChar * (size - len(padChar + originalStr)) + padChar + originalStr
        return ans

你可能感兴趣的:(LintCode:Left Pad)