Skip to content

Commit 29a0f29

Browse files
authored
Create 4000. Largest Integer With Given Digit Sum.py
1 parent 3a4e802 commit 29a0f29

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def largestInteger(self, n: int, s: int) -> int:
3+
if s==0:
4+
return 0
5+
sum_max = 0
6+
return_val = -1
7+
for num in range(10**(n-1),10**n):
8+
temp_max=0
9+
for x in str(num):
10+
temp_max += int(x)
11+
if s == temp_max:
12+
sum_max = max(sum_max,temp_max)
13+
return_val = num
14+
return return_val

0 commit comments

Comments
 (0)