-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlargest_number.py
69 lines (64 loc) · 1.24 KB
/
largest_number.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -----------------------------------------------
# Author : Mohit Chaudhari
# Created Date : 21/07/21
# -----------------------------------------------
# ***** Largest Number *****
# Problem Description
#
# Given a array A of non negative integers, arrange them such that they form the largest number.
#
# Note: The result may be very large, so you need to return a string instead of an integer.
#
#
#
# Problem Constraints
# 1 <= len(A) <= 100000
# 0 <= A[i] <= 2*109
#
#
#
# Input Format
# First argument is an array of integers.
#
#
#
# Output Format
# Return a string representing the largest number.
#
#
#
# Example Input
# Input 1:
#
# A = [3, 30, 34, 5, 9]
# Input 2:
#
# A = [2, 3, 9, 0]
#
#
# Example Output
# Output 1:
#
# "9534330"
# Output 2:
#
# "9320"
#
#
# Example Explanation
# Explanation 1:
#
# A = [3, 30, 34, 5, 9]
# Reorder the numbers to [9, 5, 34, 3, 30] to form the largest number.
# Explanation 2:
#
# Reorder the numbers to [9, 3, 2, 0] to form the largest number 9320.
class Solution:
# @param A : tuple of integers
# @return a strings
def largestNumber(self, A):
arr = [str(A[i]) for i in range(len(A))]
arr.sort()
print(arr)
s = Solution()
print(s.largestNumber([3, 30, 34, 5, 9]))