- 1
Explanation please???
here is someone's code and i don't know what lines of code 8-10 mean plz explain!!! if n == 0: return 0 s = ''.join(sorted(str(n))) c = s.count('0') s = s.replace('0', '') if s[0] != '-': s = s[0] + '0' * c + s[1:] else: s = s[:2] + '0' * c + s[2:] return int(s) print(s)
4 Réponses
+ 5
Post the whole code.
0
Here is the whole code:
def min_permutation(n):
if n == 0:
return 0
s = ''.join(sorted(str(n)))
c = s.count('0')
s = s.replace('0', '')
if s[0] != '-':
s = s[0] + '0' * c + s[1:]
else:
s = s[:2] + '0' * c + s[2:]
return int(s)
print(s)
0
Given a number, find the permutation with the smallest absolute value (no leading zeros).
-20 => -20
-32 => -23
0 => 0
10 => 10
29394 => 23499
The input will always be an integer.
0
Thank you for not replying :)