Skip to content

Commit 4820826

Browse files
authored
Create rearrange_a_string_with_integers.py
1 parent 0813650 commit 4820826

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
"""
3+
@param str: a string containing uppercase alphabets and integer digits
4+
@return: the alphabets in the order followed by the sum of digits
5+
"""
6+
def rearrange(self, str):
7+
# Write your code here
8+
count = 0
9+
ret = []
10+
for c in str:
11+
if (c < '0') or (c > '9'):
12+
ret.append(c)
13+
else:
14+
count += int(c)
15+
ret.sort()
16+
if count != 0:
17+
ret.append(count.__str__())
18+
return ''.join(ret)
19+
20+
easy: https://www.lintcode.com/problem/rearrange-a-string-with-integers

0 commit comments

Comments
 (0)