๊ธ€ ์ž‘์„ฑ์ž: ํƒ์‹œ ์šด์ „์‚ฌ
๋ฐ˜์‘ํ˜•

๐Ÿ‘ฉโ€๐Ÿซ ๋ชจ์˜๊ณ ์‚ฌ ๋ฌธ์ œ ํ’€์–ด๋ณด๊ธฐ

๐Ÿ˜ƒ ๋‚˜์˜ ์ฝ”๋“œ

def solution(answers):
    peoplePatternArray = [[1,2,3,4,5], [2,1,2,3,2,4,2,5], [3,3,1,1,2,2,4,4,5,5]]
    scoreArray = [0,0,0]
    result = []
    for idx, answer in enumerate(answers):
        for i in range(0,len(peoplePatternArray)):
            if answer == peoplePatternArray[i][idx%len(peoplePatternArray[i])]:
                scoreArray[i] += 1

    for idx, s in enumerate(scoreArray):
        if s == max(scoreArray):
            result.append(idx+1)

    return result

์™„์ „ ํƒ์ƒ‰Exhaustive Search๋ฅผ ์ด์šฉํ•˜์—ฌ ํ‘ธ๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. ์šฐ์„  ์ˆ˜ํฌ์ž 1, 2, 3์˜ ๋ฌธ์ œ ํ’€์ด ๋ฐฉ์‹์ด ์ •ํ•ด์ ธ์žˆ์œผ๋‹ˆ ์ด๋ฅผ ๋ฐฐ์—ด๋กœ ์„ ์–ธํ•ด์ค๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ฐ๊ฐ์˜ ์ดˆ๊ธฐ ์ ์ˆ˜๋ฅผ ์ดˆ๊ธฐํ™”ํ•ด์ฃผ๊ณ , ๋ฌธ์ œ 1๋ฒˆ๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰๊นŒ์ง€ ํ•™์ƒ๋“ค์˜ ๋‹ต๊ณผ ๋Œ€์กฐํ•ด๊ฐ€๋ฉด์„œ ๊ฐ๊ฐ ์ ์ˆ˜๋ฅผ ๋”ํ•ด๋‚˜๊ฐ‘๋‹ˆ๋‹ค. ์ด์ œ ๊ฐ ์ˆ˜ํฌ์ž๋ณ„ ์ ์ˆ˜๊ฐ€ ๋‚˜์™”์œผ๋‹ˆ, ๊ฐ€์žฅ ๋†’์€ ์‚ฌ๋žŒ ํ˜น์€ ๋†’์€ ์‚ฌ๋žŒ๋“ค์„ ๋ฐ˜ํ™˜ํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ๋งˆ๋ฌด๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

Written with StackEdit.

๋ฐ˜์‘ํ˜•