Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Largest Number in python #770

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Data Structures/Arrays/LargestNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'''

Given a list of non negative integers, arrange them such that they form the largest number.

Ex : [3, 30, 34, 5, 9], the largest formed number is 9534330.
'''

class Solution:
def largestNumber(self, a):
# write your method here

largestnumber =''
for i in range(len(a)-1):
for j in range(i+1, len(a)):
string1 = str(a[i])+str(a[j])
string2 = str(a[j])+str(a[i])
if int(string2) > int(string1):
a[i] , a[j] = a[j] , a[i]
for i in range(len(a)):
largestnumber += str(a[i])
return int(largestnumber)