전체 글 (42) 썸네일형 리스트형 프로그래머스 추억 점수 PYTHON 추억 점 def solution(name, yearning, photo): answer = [] count = 0 dic = dict(zip(name,yearning)) for i in range(len(photo)): for j in range(len(photo[i])): if photo[i][j] in dic: count += dic[photo[i][j]] answer.append(count) count = 0 return answer name과 yearning을 딕셔너리로 저장해준다음 photo에서를 순회하면서 이름에 추억도가 반영되있는경우 값들을 더해 answer에 추가해주었다. 프로그래머스 K번째수 PYTHON def solution(array, commands): answer = [] result = [] for i in range(len(commands)): answer.append(array[commands[i][0]-1:commands[i][1]]) answer[i] = sorted(answer[i]) result.append(answer[i][commands[i][2]-1]) return result commands의 값들을 가지고 array의 값을 슬라이싱한후 정렬한뒤 원하는 값을 저장하면 되는 문제이다. 프로그래머스 삼총사 PYTHON import itertoolsdef solution(number): answer = [] result = [] count = 0 combination = itertools.combinations(number,3) for combo in combination: answer.append(combo) for i in range(len(answer)): result.append(sum(answer[i])) count = result.count(0) return count number list에서 3가지수를 뽑아서 3가지수의 합의 개수를 return 하는 문제이다. 여기서 살짝 어려웠던점이 어떻게 3가를 뽑을것이었다.하지만 파이썬에는 iterto.. 프로그래머스 최소직사각형 PYTHON def solution(sizes): max_width = 0 max_height = 0 for size in sizes: width, height = sorted(size) max_width = max(max_width, width) max_height = max(max_height, height) return max_width * max_height직사각형의 가로부분과 세로부분을 정렬하여, 가장큰 가로값과 가장큰 세로값을 곱해주면 된다. 프로그래머스 이상한 문자 만들기 PYTHON def solution(s): answer = '' result = [] s = s.split(" ") for i in range(len(s)): for j in range(len(s[i])): if j%2==0: answer += s[i][j].upper() elif j%2==1: answer +=s[i][j].lower() result.append(answer) answer ="" return ' '.join(result)이문제를 처음풀때 다른부분은 매우 쉬웠는데 공백을 처리하는 부분에서 고민을 많이한것같다. 공백을 기준으로 문자를 나누고,for.. 프로그래머스 정수를 나선형으로 배치하기 python def solution(n): if n == 1: return [[1]] answer = [[0]*n for _ in range(n)] x = 0 y = 0 direction = 'r' for i in range(n*n): answer[x][y] = i + 1 if direction == 'r': y += 1 if y == n-1 or answer[x][y+1] != 0: direction = 'd' elif direction == 'd': x += 1 if x == n-1 or answer[x+1][y] != 0: .. 프로그래머스 옹알이 (1) level0 python def solution(babbling): answer = [] string = '' count = 0 for i in range(len(babbling)): for j in range(len(babbling[i])): string += babbling[i][j] if string == 'aya': string = '' elif string == 'ye': string = '' elif string == 'woo': string = '' elif string == "ma": .. 프로그래머스 겹치는 선분의 길이 level0 python def solution(lines): answer = 0 total = [] first = list(set(range(lines[0][0], lines[0][1])) & set(range(lines[1][0], lines[1][1]))) second = list(set(range(lines[0][0], lines[0][1])) & set(range(lines[2][0], lines[2][1]))) third = list(set(range(lines[1][0], lines[1][1])) & set(range(lines[2][0], lines[2][1]))) total = first + second + third answer = (len(set(total))) .. 이전 1 2 3 4 5 6 다음 목록 더보기