Skip to content

Commit 82deca3

Browse files
committed
左填充
1 parent d686864 commit 82deca3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

left_pad.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class StringUtils:
2+
# @param {string} originalStr the string we want to append to
3+
# @param {int} size the target length of the string
4+
# @param {string} padChar the character to pad to the left side of the string
5+
# @return {string} a string
6+
@classmethod
7+
def leftPad(self, originalStr, size, padChar=' '):
8+
# Write your code here
9+
result = ''
10+
dist = size - len(originalStr)
11+
if dist > 0:
12+
for i in xrange(dist):
13+
result += padChar
14+
return result + originalStr
15+
else:
16+
return originalStr

0 commit comments

Comments
 (0)