LintCode Q524 Left Pad in Python

  • Jinhai ZHOU
  • 2 Minutes
  • 2017年2月14日
1
2
3
4
5
6
7
8
9
10
11
12
13
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
offset = size - len(originalStr)
string = padChar * offset
return string + originalStr
知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。