๐Ÿ—๏ธ Algorithm/โฌ› ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

โฌ› [Programmers] [Python] [Level1] ํ‘ธ๋“œ ํŒŒ์ดํŠธ ๋Œ€ํšŒ

Dbswnstjd 2023. 4. 10. 15:34

๋ฌธ์ œ

https://school.programmers.co.kr/learn/courses/30/lessons/134240

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

ํ’€์ด

# ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 1๋‹จ๊ณ„ - ํ‘ธ๋“œ ํŒŒ์ดํŠธ ๋Œ€ํšŒ
def solution(food):
    answer = ''
    res = ''
    for i in range(1, len(food)):
        if food[i] >= 2:
            res += (food[i]//2)*str(i)
    answer = res + str(0) + res[::-1] 
    return answer

print(solution([1,3,4,6]))