[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ •๋ ฌ - ๊ฐ€์žฅ ํฐ ์ˆ˜

๋ฌธ์ œ

๋ฌธ์ œ ์„ค๋ช…

0 ๋˜๋Š” ์–‘์˜ ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ •์ˆ˜๋ฅผ ์ด์–ด ๋ถ™์—ฌ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๊ฐ€์žฅ ํฐ ์ˆ˜๋ฅผ ์•Œ์•„๋‚ด ์ฃผ์„ธ์š”.

์˜ˆ๋ฅผ ๋“ค์–ด, ์ฃผ์–ด์ง„ ์ •์ˆ˜๊ฐ€ [6, 10, 2]๋ผ๋ฉด [6102, 6210, 1062, 1026, 2610, 2106]๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ณ , ์ด์ค‘ ๊ฐ€์žฅ ํฐ ์ˆ˜๋Š” 6210์ž…๋‹ˆ๋‹ค.

0 ๋˜๋Š” ์–‘์˜ ์ •์ˆ˜๊ฐ€ ๋‹ด๊ธด ๋ฐฐ์—ด numbers๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ์ˆœ์„œ๋ฅผ ์žฌ๋ฐฐ์น˜ํ•˜์—ฌ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๊ฐ€์žฅ ํฐ ์ˆ˜๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊พธ์–ด return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ ์‚ฌํ•ญ

  • numbers์˜ ๊ธธ์ด๋Š” 1 ์ด์ƒ 100,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค.
  • numbers์˜ ์›์†Œ๋Š” 0 ์ด์ƒ 1,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค.
  • ์ •๋‹ต์ด ๋„ˆ๋ฌด ํด ์ˆ˜ ์žˆ์œผ๋‹ˆ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊พธ์–ด return ํ•ฉ๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ

numbers return
[6, 10, 2] โ€œ6210โ€
[3, 30, 34, 5, 9] โ€œ9534330โ€

ํ’€์ด

Python
def solution(numbers):
    answer = ''

    numbers = list(map(str, numbers))  # numbers ๋ฐฐ์—ด ์›์†Œ ํƒ€์ž…์„ strํ˜•์œผ๋กœ
    numbers.sort(key=lambda x:x*3, reverse=True)  # numbers๋Š” 1,000์ดํ•˜์˜ ์›์†Œ๋“ค๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ ์›์†Œ๋“ค์„ 3์ž๋ฆฌ ์ˆ˜๋กœ ๋งŒ๋“ค์–ด ์•ž์—์„œ๋ถ€ํ„ฐ 3์ž๋ฆฌ๊นŒ์ง€ ํฌ๊ธฐ๋ฅผ ๋น„๊ตํ•จ

    answer = str(int(''.join(numbers)))  # numbers=[0, 0, 0]์˜ ๊ฒฝ์šฐ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด intํ˜•์œผ๋กœ ๋ฐ”๊พผ ๋’ค strํ˜•์œผ๋กœ
    return answer

๐Ÿ’ก ์›์†Œ๋ฅผ 3์ž๋ฆฌ์ˆ˜๋กœ ๋ฐ”๊ฟ”์ฃผ์–ด ๋ฌธ์ž์—ด๋ผ๋ฆฌ ํฌ๊ธฐ ๋น„๊ต๋ฅผ ํ•˜๋Š” ๊ฒƒ์ด ํ•ต์‹ฌ!



๋ฒˆ์™ธ - ํšจ์œจ์„ฑ์—์„œ ๋น ๊พธ๋จน์€ ํ’€์ด

/src/assets/the-biggest-number.py
from itertools import permutations

def solution(numbers):
    answer = ''

    for per in permutatins(numbers):
        target = ''
        for num in per:
            target += str(num)
        answer = max(answer, target)

    return answer

๐Ÿ˜…

  • ์ˆœ์—ด์„ ์ด์šฉํ•˜์—ฌ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ์ˆœ์„œ์˜ ๋ฌธ์ž์—ด ์กฐํ•ฉ์„ ๊ตฌํ•œ ๋’ค ํ•˜๋‚˜์”ฉ ํฌ๊ธฐ๋ฅผ ๋น„๊ตํ•˜๋Š” ๋ฐฉ์‹
  • ๋ชจ๋“  ํ…Œ์ผ€์—์„œ ์‹œ๊ฐ„์ดˆ๊ณผโ€ฆ;
  • numbers ๋ฐฐ์—ด์˜ ์ตœ๋Œ€ ๊ธธ์ด๊ฐ€ 100,000์ด๋ฏ€๋กœ ๋ชจ๋“  ์ˆœ์—ด์„ ๊ตฌํ•˜๋Š” ๊ฒƒ์ด ์‹œ๊ฐ„์ด ์˜ค๋ž˜๊ฑธ๋ฆฌ๋Š” ๊ฒƒ ๊ฐ™์Œ!