[BaekJoon] 1439๋ฒˆ : ๋’ค์ง‘๊ธฐ

Updated:

1439๋ฒˆ : ๋’ค์ง‘๊ธฐ


์ด๊ฒƒ์ด ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ๋‹ค ๊ทธ๋ฆฌ๋”” ์˜ˆ์ œ ๋ฌธ์ œ์ด๋‹ค.

๊ทธ๋ฆฌ๋””๋Š” ํ˜„์žฌ ์ƒํ™ฉ๋งˆ๋‹ค ๊ฐ€์žฅ ์ข‹์€ ๊ฒƒ์„ ์„ ํƒํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ธ๋ฐ ์™œ ์ด๊ฒŒ ๊ทธ๋ฆฌ๋”” ์˜ˆ์‹œ์ธ์ง€ ์ดํ•ด๊ฐ€ ์•ˆ๊ฐ„๋‹ค..

์–ด์จŒ๋“  0์˜ ๋ฉ์–ด๋ฆฌ ๊ฐœ์ˆ˜, 1์˜ ๋ฉ์–ด๋ฆฌ ๊ฐœ์ˆ˜ ์ค‘ ์ ์€ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค.


from collections import deque


def solution(str):
	nums = deque(map(int, str))
	work = [0, 0]

	before = nums.popleft()
	while nums:
		now = nums.popleft()
		if before == now:
			before = now
			continue
		else:
			work[before] += 1
			before = now
	work[now] += 1

	return min(work)


if __name__ == '__main__':
	str = input()
	print(solution(str))



Categories:

Updated:

Leave a comment