[HackerRank][Python3] Big Sorting
2018. 5. 29. 00:57 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/big-sorting/problem
My Solution :
#!/usr/bin/env python3
def bigSorting(unsorted):
dic = {}
ret = []
for s in unsorted:
dic.setdefault(len(s), []).append(s)
for k in sorted(dic):
for s in sorted(dic[k]):
ret.append(s)
return ret
n = int(input())
unsorted = []
for _ in range(n):
unsorted_item = input()
unsorted.append(unsorted_item)
result = bigSorting(unsorted)
for s in result:
print(s)
My Solution2 :
#!/usr/bin/env python3
def bigSorting(unsorted):
return sorted(unsorted, key=lambda x:(len(x), x))
n = int(input())
unsorted = []
for _ in range(n):
unsorted_item = input()
unsorted.append(unsorted_item)
result = bigSorting(unsorted)
for s in result:
print(s)
'프로그래밍 > HackerRank' 카테고리의 다른 글
| [HackerRank][Python3] Climbing the Leaderboard (0) | 2018.06.01 |
|---|---|
| [HackerRank][Python3] The Power Sum (1) | 2018.05.31 |
| [HackerRank][Python3] Construct the Array (0) | 2018.05.30 |
| [HackerRank][Python3] Minimum Absolute Difference in an Array (0) | 2018.05.29 |
| [HackerRank][Python3] CamelCase (0) | 2018.05.27 |
| [HackerRank][Python3] Journey to the Moon (0) | 2018.05.25 |
| [HackerRank][Python3] Hackerland Radio Transmitters (0) | 2018.05.23 |
| [HackerRank][Python3] Sherlock and Cost (0) | 2018.05.21 |
최근에 달린 댓글 최근에 달린 댓글