본문 바로가기

알고리즘/프로그래머스

(72)
[Python] [1차] 뉴스 클러스터링 https://school.programmers.co.kr/learn/courses/30/lessons/17677 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 나의 풀이(틀림) # [1차] 뉴스 클러스터링 def solution(str1, str2): import math import re str1 = str1.lower() str2 = str2.lower() str1 = re.sub(r'[^a-z]', ' ', str1) str2 = re.sub(r'[^a-z]', ' ', str2) set_1 = [] set_2 = [] for i in range(..
[Python] 프린터 https://school.programmers.co.kr/learn/courses/30/lessons/42587 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr # 프린터 def solution(priorities, location): idx = [x for x in range(len(priorities))] print_sequence = priorities.copy() i = 0 while True: if print_sequence[i] < max(print_sequence[i+1:]): idx.append(idx.pop(i)) print_sequenc..
[Python] 모의 고사 https://school.programmers.co.kr/learn/courses/30/lessons/42840 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 나의 풀이 # 모의고사 def solution(answers): supo_1 = 0 supo_2 = 0 supo_3 = 0 supo_1_pattern = [1,2,3,4,5] * 8 supo_2_pattern = [2,1,2,3,2,4,2,5] * 5 supo_3_pattern = [3,3,1,1,2,2,4,4,5,5] * 4 for i in range(len(answers)): idx = i %..
[Python] 소수 찾기 https://school.programmers.co.kr/learn/courses/30/lessons/12921 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 나의 풀이 # 소수 찾기 def solution(n): import math answer = 0 for i in range(2, n+1): error = 0 for j in range(2, int(math.sqrt(i)+1)): # 제곱근 까지만 반복 if i % j == 0: error += 1 break if error == 0: answer += 1 return answer 다른 풀이 def..
[Python] n^2 배열 자르기 https://school.programmers.co.kr/learn/courses/30/lessons/87390 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 나의 풀이 # n^2 배열 자르기 def solution(n, left, right): array = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): if j
[Python] 최고의 집합 https://school.programmers.co.kr/learn/courses/30/lessons/12938 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 첫 번째 풀이 from functools import reduce def combinations_with_replacement(iterable, r): # combinations_with_replacement('ABC', 2) --> AA AB AC BB BC CC pool = tuple(iterable) n = len(pool) if not n and r: return indices = [0] ..
[Python] 기능 개발 https://school.programmers.co.kr/learn/courses/30/lessons/42586 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr # 기능 개발 def solution(progresses, speeds): import math need_days = [] # 각 기능 개발까지 필요한 날짜 for x, y in zip(progresses, speeds): need_day = math.ceil((100 - x) / y) need_days.append(need_day) answer = [] threshold = need_days[0..
[Python] 이중 우선순위 큐 https://school.programmers.co.kr/learn/courses/30/lessons/42628 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(operations): answer = [] for i in operations: oper = i.split() if oper[0] == 'I': answer.append(int(oper[1])) elif oper[0] == 'D': if answer == []: continue else: if oper[1] == '1': answer.remove(max(answer)) e..