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

[Programmers] [์›”๊ฐ„ ์ฝ”๋“œ ์ฑŒ๋ฆฐ์ง€ ์‹œ์ฆŒ3] [Python] Level2_n^2 ๋ฐฐ์—ด ์ž๋ฅด๊ธฐ

Dbswnstjd 2022. 10. 26. 04:31

๋ฌธ์ œ

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

 

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

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

programmers.co.kr

ํ’€์ด

# ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - n^2 ๋ฐฐ์—ด ์ž๋ฅด๊ธฐ
def solution(n,left,right):
    answer = []
    for i in range(left, right+1):
        answer.append((max(i//n, i%n))+1)
    return answer

์ฒ˜์Œ์— ์ด์ค‘ for๋ฌธ์„ ์‚ฌ์šฉํ•˜์˜€์œผ๋‚˜ ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋–ณ๋‹ค.

๊ทธ๋ž˜์„œ ๊ทœ์น™์„ ์ฐพ์•„์„œ ํ•ด๊ฒฐํ•˜์˜€๋‹ค.