๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐˜ผ๐™ก๐™œ๐™ค๐™ง๐™ž๐™ฉ๐™๐™ข/๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™š๐™ง๐™จ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค '์Šคํ‚ฌํŠธ๋ฆฌ' ํŒŒ์ด์ฌ ํ’€์ด

by beomcoder 2023. 7. 10.
728x90
๋ฐ˜์‘ํ˜•
https://school.programmers.co.kr/learn/courses/30/lessons/49993
 

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

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

programmers.co.kr

 

def solution(skill, skill_trees):
    answer = 0
    for skill_tree in skill_trees:
        _max = -1
        for step in skill_tree:
            if step in skill and skill.index(step) != (_max:=_max+1): break
        else: answer += 1
    
    return answer
 
"""
for-else ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ’€์—ˆ๋‹ค.
for-else๋Š” for๋ฌธ์ด ์™„์ „ํžˆ ๋๋‚˜๊ธฐ ์ „์— for๋ฌธ์ด ์ข…๋ฃŒ๋˜๋ฉด
else๋ฌธ์„ ๊ฑฐ์น˜์ง€ ์•Š๋Š”๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด 1~10๊นŒ์ง€ for๋ฌธ์„ ๋Œ๋ฆฌ๋Š”๋ฐ, 5์—์„œ ์ข…๋ฃŒ๋˜๋ฉด else๋ฅผ ๊ฑฐ์น˜์ง€ ์•Š๋Š”๋‹ค.
10๊นŒ์ง€ ์™„์ „ํžˆ ๋๋‚œ๋‹ค๋ฉด else๋ฅผ ๊ฑฐ์นœ๋‹ค.
"""
728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€