[Programmers] ๋‹คํŠธ๊ฒŒ์ž„
ยท
๐Ÿ’ฏ CodingTest/Programmers
โ–ถ ๋ฌธ์ œ : ๋”๋ณด๊ธฐ https://programmers.co.kr/learn/courses/30/lessons/17682 โ–ถ ์ฝ”๋“œ : def solution(dartResult): numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] divided = [] answer = [] temp = '' for i in range(len(dartResult)): if dartResult[i] in numbers and i == 0: temp += dartResult[i] elif dartResult[i] in numbers and dartResult[i-1] not in numbers: divided.append(temp) temp = dartRe..
[Programmers] ๋น„๋ฐ€์ง€๋„
ยท
๐Ÿ’ฏ CodingTest/Programmers
โ–ถ ๋ฌธ์ œ : ๋”๋ณด๊ธฐ https://programmers.co.kr/learn/courses/30/lessons/17681 โ–ถ ์ฝ”๋“œ : def solution(n, arr1, arr2): answer = [] for i in range(n): bitStr = bin(arr1[i] | arr2[i]) temp = '' bitStr = bitStr[2:] bitStr = bitStr.rjust(n,'0') #bin() ์„ ์ด์šฉํ•˜๋ฉด ๋งจ์•ž์— 0์ธ ๋ถ€๋ถ„์„ ์—†์• ๋ฒ„๋ฆฌ๊ธฐ์— ๊ธธ์ด๋ฅผ ๋งž์ถฐ์ค˜์•ผํ•จ => ์ฃผ์˜ #bitStr์—๋Š” '0b' ๊ฐ€ ์•ž์— ํฌํ•จ๋˜์–ด์žˆ์Œ for c in bitStr: if c == '1': temp += '#' elif c == '0': temp += ' ' answer.append(temp) return a..
[Programmers] ์‹คํŒจ์œจ
ยท
๐Ÿ’ฏ CodingTest/Programmers
โ–ถ ๋ฌธ์ œ : ๋”๋ณด๊ธฐ https://programmers.co.kr/learn/courses/30/lessons/42889 โ–ถ ์ฝ”๋“œ : def solution(N, stages): answer= [] totalUser=len(stages) count = {} for i in range(N): count[i+1] = 0 stages.sort() for stage in stages: if stage == N+1: continue else: count[stage] += 1 failure = {} for i in range(1,N+1): if totalUser == 0: failure[i] = 0 else: failure[i] = count[i]/totalUser totalUser -= count[i] answe..
[Programmers] ํฌ๋ ˆ์ธ ์ธํ˜•๋ฝ‘๊ธฐ ๊ฒŒ์ž„
ยท
๐Ÿ’ฏ CodingTest/Programmers
โ–ถ ๋ฌธ์ œ : ๋”๋ณด๊ธฐ https://programmers.co.kr/learn/courses/30/lessons/64061 โ–ถ ์ฝ”๋“œ : from collections import deque def solution(board, moves): count = 0 st = deque() for num in moves: for i in range(len(board)): item = board[i][num-1] if item == 0: continue else: if len(st) != 0: recent_item = st.popleft() if recent_item == item: count += 2 else: st.appendleft(recent_item) st.appendleft(item) else: st.app..
[Programmers] ํ‚คํŒจ๋“œ ๋ˆ„๋ฅด๊ธฐ
ยท
๐Ÿ’ฏ CodingTest/Programmers
โ–ถ ๋ฌธ์ œ : ๋”๋ณด๊ธฐ https://programmers.co.kr/learn/courses/30/lessons/67256 โ–ถ ์ฝ”๋“œ : keyPad = { '1' : (0,0), '2' : (0,1), '3' : (0,2), '4' : (1,0), '5' : (1,1), '6' : (1,2), '7' : (2,0), '8' : (2,1), '9' : (2,2), '*' : (3,0), '0' : (3,1), '#' : (3,2) } def solution(numbers, hand): answer='' left = '*' right = '#' for num in numbers: if num in [1, 4, 7] : answer += 'L' left = str(num) elif num in [3, 6, 9]..
[Programmers] ์ˆซ์ž ๋ฌธ์ž์—ด๊ณผ ์˜๋‹จ์–ด
ยท
๐Ÿ’ฏ CodingTest/Programmers
๋ฌธ์ œ ์‚ฌ์ดํŠธ ๋”๋ณด๊ธฐ https://programmers.co.kr/learn/courses/30/lessons/81301 โ–ถ ์ฝ”๋“œ def solution(s): words = {'zero': '0', 'one':'1', 'two':'2', 'three':'3','four':'4', 'five':'5', 'six':'6', 'seven':'7','eight':'8','nine':'9'} temp = '' answer = '' for c in s: if c in words.values() : answer += c else: temp += c if temp in words.keys() : answer += words[temp] temp = '' return int(answer) โ–ถ ๋ฌธ์ œ ํ’€์ด 1. ์ดˆ๊ธฐ `wo..
[Programmers] ์‹ ๊ณ ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ
ยท
๐Ÿ’ฏ CodingTest/Programmers
๋ฌธ์ œ ํŽ˜์ด์ง€ ๋”๋ณด๊ธฐ https://programmers.co.kr/learn/courses/30/lessons/92334 def solution(id_list, report, k): count = dict() reportCount = dict() report = list(set(report)) # ๋™์ผ ์‹ ๊ณ ์— ๋Œ€ํ•œ ์ค‘๋ณต๊ฐ’ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด set ๋ณ€ํ™˜ ํ›„ list ๋ณ€ํ™˜ for id in id_list: # ๋”•์…”๋„ˆ๋ฆฌ ์ดˆ๊ธฐํ™” count[id] = 0 reportCount[id] = 0 for str in report : # report์— ์ €์žฅ๋œ ๊ฐ๊ฐ์˜ ๋ฌธ์ž์—ด ํŒŒ์‹ฑํ•ด ์‹ ๊ณ  ํšŸ์ˆ˜ ๋ˆ„์  src, trg = str.split(' ') count[trg] += 1 for str in report : # src, trg =..