Skip to content

Commit fa90f80

Browse files
committed
1 parent e04ca8a commit fa90f80

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Hongjoo/lv2/가장큰수.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
실패
3+
1. 가장 큰 자리수 비교 -> 자리수 가장 작은 수
4+
0. graph
5+
idx : numbers
6+
value : [0,0,0,-1] # ex 62 => [6,2,False,False]
7+
# 조건 2.
8+
3,30,300 비교 -> 3 > 30> 300 우선순위
9+
#반례
10+
1) 110 vs 1 > 1+110
11+
2) [12, 1213] -> 1213+12
12+
"""
13+
14+
def solution(numbers):
15+
answer = ''
16+
#0. graph 만들기
17+
graph = list()
18+
for n in numbers:
19+
p = 4-len(str(n))
20+
if p > 0 :
21+
douple_n = str(n)*p
22+
else :
23+
douple_n = str(n)
24+
graph.append([douple_n[:4], p ]) # 자리수 맞춰주기(4자리)
25+
# print(graph)
26+
#2.정렬 : 높은 자리수의 값이 큰 순서 대로
27+
graph.sort(key=lambda x : x[0] , reverse = True)
28+
# print(graph)
29+
#3. 합치기
30+
answer=""
31+
for i in range(len(graph)):
32+
num = graph[i][0] ; position = 4-graph[i][1]
33+
answer += str(int(num[:position]))# "000","0" 경우 0으로 처리
34+
35+
return answer

0 commit comments

Comments
 (0)