Coding/Code in the Morning

220117_Code in the morning (์ฃผ์‹๊ฐ€๊ฒฉ)

๊น€์œ ๋‹ˆ์ฝ˜ 2022. 1. 17. 12:19

Code in the morning, ๋งค์ผ ์•„์นจ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ๋ฅผ ํ’‰๋‹ˆ๋‹ค. 

๐Ÿ’ฌ ๋ฌธ์ œ ์„ค๋ช…: ์ฃผ์‹๊ฐ€๊ฒฉ

์ดˆ ๋‹จ์œ„๋กœ ๊ธฐ๋ก๋œ ์ฃผ์‹๊ฐ€๊ฒฉ์ด ๋‹ด๊ธด ๋ฐฐ์—ด prices๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๊ฐ€๊ฒฉ์ด ๋–จ์–ด์ง€์ง€ ์•Š์€ ๊ธฐ๊ฐ„์€ ๋ช‡ ์ดˆ์ธ์ง€๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•˜์„ธ์š”.

 

 

๐Ÿ“ ์ œํ•œ ์‚ฌํ•ญ

  • prices์˜ ๊ฐ ๊ฐ€๊ฒฉ์€ 1 ์ด์ƒ 10,000 ์ดํ•˜์ธ ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค.
  • prices์˜ ๊ธธ์ด๋Š” 2 ์ด์ƒ 100,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช…

  • 1์ดˆ ์‹œ์ ์˜ โ‚ฉ1์€ ๋๊นŒ์ง€ ๊ฐ€๊ฒฉ์ด ๋–จ์–ด์ง€์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.
  • 2์ดˆ ์‹œ์ ์˜ โ‚ฉ2์€ ๋๊นŒ์ง€ ๊ฐ€๊ฒฉ์ด ๋–จ์–ด์ง€์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.
  • 3์ดˆ ์‹œ์ ์˜ โ‚ฉ3์€ 1์ดˆ๋’ค์— ๊ฐ€๊ฒฉ์ด ๋–จ์–ด์ง‘๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ 1์ดˆ๊ฐ„ ๊ฐ€๊ฒฉ์ด ๋–จ์–ด์ง€์ง€ ์•Š์€ ๊ฒƒ์œผ๋กœ ๋ด…๋‹ˆ๋‹ค.
  • 4์ดˆ ์‹œ์ ์˜ โ‚ฉ2์€ 1์ดˆ๊ฐ„ ๊ฐ€๊ฒฉ์ด ๋–จ์–ด์ง€์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.
  • 5์ดˆ ์‹œ์ ์˜ โ‚ฉ3์€ 0์ดˆ๊ฐ„ ๊ฐ€๊ฒฉ์ด ๋–จ์–ด์ง€์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

 

๐Ÿ’ก ๋‚˜์˜ ํ’€์ด 

def solution(prices):
    answer = []
    for i in range (0, len(prices)):
        cnt = 0
        for j in range (i+1, len(prices)):
            if prices[i] <= prices[j] :
                cnt += 1 
                
            elif prices[i] > prices[j] :
                cnt = j-i
                break
        answer.append(cnt)
                
    return answer

 

 

ํšจ์œจ์„ฑ ํ…Œ์ŠคํŠธ๋ฅผ ํ†ต๊ณผํ•˜์ง€ ๋ชปํ• ๊นŒ๋ด ์กฐ๋งˆ์กฐ๋งˆํ–ˆ๋‹ค. 

๐Ÿ‘‰๐Ÿป ๋ฌธ์ œ ๋ฐ”๋กœ๊ฐ€๊ธฐ