ํŒŒ์ด์ฌ 3

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค lvl.2] ์ ํ”„์™€ ์ˆœ๊ฐ„์ด๋™ - python

๐Ÿ“‹ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Level.2 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด def solution(n): ans = 0 if n == 0: ans+= 0 while(n>0): if n%2 == 0: # print('n is even',n,ans) n=int(n/2) else: # print('n is odd',n,ans) n=int((n-1)/2) ans+=1 return ans top down์œผ๋กœ ํ’€์–ด์•ผ ๋” ๋น ๋ฅผ๊ฒƒ๊ฐ™์•„์„œ ์œ„์—์„œ๋ถ€ํ„ฐ 2๋กœ ๋‚˜๋ˆ„์–ด ์ฃผ๋ฉด์„œ ์‹œ์ž‘ํ–ˆ๋‹ค.. ์–ด๋ ต์ง€ ์•Š์€ ๋ฌธ์ œ์ด์ง€๋งŒ ์˜ฌ๋ฆฌ๋Š” ์ด์œ ๋Š”!! ๐Ÿ“” ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ์ฝ”๋“œ de..

Coding Test 2023.10.20

[Dynamic Programming] ์ตœ์†Œ ๋น„์šฉ ๊ตฌํ•˜๊ธฐ - ์ดˆ๊ธ‰

์œ ํŠญ ๋งใ…‹ ๐Ÿ“‹ LeetCode 64๋ฒˆ Minimum Path Sum - LeetCode Can you solve this real interview question? Minimum Path Sum - Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. Note: You can only move either down or rig leetcode.com grid cost [[ 1, 3, 1 ], [[ 1, 4, 5 ], [ 1, 5, 1 ], → [ 2, _, _ ], [ 4, 2, 1 ]] ..

[Dynamic Programming] ๊ณ„๋‹จ ์˜ค๋ฅด๊ธฐ - ์ดˆ๊ธ‰

→ ๐Ÿ“‹ LeetCode 70๋ฒˆ Climbing Stairs - LeetCode Can you solve this real interview question? Climbing Stairs - You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example 1: Input: n = 2 Outpu leetcode.com ์˜ฌ๋ผ๊ฐ€์•ผ ํ•˜๋Š” ๊ณ„๋‹จ์˜ ์ˆ˜: n n์œผ๋กœ ์˜ฌ๋ผ๊ฐ€๊ธฐ ์œ„ํ•œ ๊ฒฝ์šฐ์˜ ์ˆ˜๋Š” n-1์—์„œ 1์นธ or n-2์—์„œ 2์นธ ์˜ฌ๋ผ ๊ฐ€๋Š” ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. -> ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜์™€ ..