์ƒˆ์†Œ์‹

๐Ÿงฎ PS

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] (Python) - ํฌ๋ ˆ์ธ ์ธํ˜•๋ฝ‘๊ธฐ ๊ฒŒ์ž„

  • -

* ๋ฌธ์ œ ๋งํฌ

programmers.co.kr/learn/courses/30/lessons/64061

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํฌ๋ ˆ์ธ ์ธํ˜•๋ฝ‘๊ธฐ ๊ฒŒ์ž„

[[0,0,0,0,0],[0,0,1,0,3],[0,2,5,0,1],[4,2,4,4,2],[3,5,1,3,1]] [1,5,3,5,1,2,1,4] 4

programmers.co.kr

 

* ๋ฌธ์ œ ๋ถ„๋ฅ˜ , ๋‚œ์ด๋„

 

 ๋ถ„๋ฅ˜ : 2019 ์นด์นด์˜ค ๊ฐœ๋ฐœ์ž ๊ฒจ์šธ ์ธํ„ด์‰ฝ

 ๋‚œ์ด๋„ : Lv1

 

* ํŒŒ์ด์ฌ(Pyhton) ์ฝ”๋“œ

 

def drop_in_basket(board, move, basket):
	for i in range(len(board)) : 
		if (board[i][move-1] != 0 ) :
			basket.append(board[i][move-1])
			board[i][move-1] = 0
			return 1
	return 0

def boom_check(basket, idx) :
	if len(basket) >= 2  :
		for i in range(1, len(basket)) :
			if (basket[i-1] == basket[i]) :
				del basket[i-1]
				del basket[i-1]
				return 1

def solution(board, moves):
	basket = []
	answer = 0
	for idx in range(len(moves)) :
		if drop_in_basket(board, moves[idx], basket) :
			if boom_check(basket, idx) : 
				answer += 2
	return answer

 

* ํ’€์ด ๋ฐฉ๋ฒ•

 

  • drop_in_basket : board(list)์—์„œ ๋ฝ‘์€ ์ธํ˜•์„ basket(list)์— ๋‹ด๊ณ , ์ด๋ฏธ ๋ฝ‘์€ ์ธํ˜•์ž๋ฆฌ์— 0์„ ๋„ฃ์–ด์ฃผ๋Š” ํ•จ์ˆ˜ 
  • boom_check : ๊ฐ™์€ ์ข…๋ฅ˜์˜ ์ธํ˜•์ด ์—ฐ์†ํ•˜์—ฌ basket(list)์— ์Œ“์˜€์„๋•Œ, 2๊ฐœ์˜ ์ธํ˜•์„ ์‚ญ์ œํ•˜๋Š” ํ•จ์ˆ˜

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.