프로그래머스 20

[프로그래머스] 해시 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/42576 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 from collections import defaultdict def solution(participant, completion): hash_table = defaultdict(int) for i in participant: hash_table[i] += 1 for i in completion: hash_table[i] -= 1 if hash_table[i] == 0: del hash_..

BOJ/Python 2024.03.23

[프로그래머스] 의상 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/42578 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 답안 from collections import defaultdict def solution(clothes): dic = defaultdict(int) answer = 1 for _, y in clothes: dic[y] += 1 for _, j in dic.items(): answer *= (j+1) return answer-1 Review 이 문제는 보자마자 구현이 아닌 수학적으로 접근해야..

BOJ/Python 2024.02.12

[프로그래머스] 키패드 누르기 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/67256 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 보기 더보기 내 코드 def judge(start, end): 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) } start_distance = ..

BOJ/Python 2023.11.24

[프로그래머스] 신고 결과 받기 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/92334 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 보기 더보기 내 코드 from collections import defaultdict def solution(id_list, report, k): answer = [0] * len(id_list) report_count = defaultdict(int) for i in set(report): report_count[i.split()[1]] += 1 filtered_set = {key for ..

BOJ/Python 2023.11.20

[프로그래머스] 카펫 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/42842 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 보기 더보기 내 코드 def solution(brown, yellow): d = [] n = brown + yellow # n : 전체 블럭의 수 for i in range(1, int(n**(1/2)) + 1): # 약수 모음 if (n % i == 0): d.append(i) if ( (i**2) != n) : d.append(n // i) d.sort() for i in range(le..

프로그래머스 2023.09.20

[프로그래머스] 3진법 뒤집기 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/68935 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(n): answer = '' result = 0 while n > 0: answer = str(n % 3) + answer n //= 3 for i in range(len(answer)): result += (int(answer[i]) * 3**i) return result Review 문제를 다 풀고 나서 남들이 푼 코드를 보다가 저번에 n 진법 관련 문제를 풀던..

프로그래머스 2023.06.24

[프로그래머스] 더 맵게 파이썬 heapq

https://school.programmers.co.kr/learn/courses/30/lessons/42626 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 import heapq def solution(scoville, K): heapq.heapify(scoville) cnt = 0 while scoville[0] = 2: min_1 = heapq.heappop(scoville) min_2 = heapq.heappop(scoville) heapq.heappush(scoville, min_1 + (mi..

프로그래머스 2023.06.23

[프로그래머스] 정수 제곱근 판별 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/12934 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(n): a = n ** 0.5 if a == int(a): return (a+1) ** 2 else: return -1 Review n ** 0.5 을 하면 float 타입이 반환이 된다. 루트 씌운 n 값을 정수형(n) 값과 비교해서 같으면 정수 제곱근이다. ex ) n = 121 일때 √n = 11.0 11.0 == int(11.0) True -> 정수 제곱근 ..

프로그래머스 2023.06.20

[프로그래머스] [1차] 캐시

https://school.programmers.co.kr/learn/courses/30/lessons/17680 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 # 1차 캐시 from collections import deque def solution(cacheSize, cities): cache = deque([]) cities = map(lambda x: x.lower(), cities) # 모두 소문자로 구분 hit = 1 miss = 5 result = 0 for i in cities: if not i in cache and len(cac..

프로그래머스 2023.06.02

[프로그래머스] 주차 요금 계산 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/92341 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 import math def solution(fees, records): default = 1439 # 23:59 result = {} answer = [] # 차 번호순으로 정렬후 뒤집어 정렬 lst = reversed(sorted(records, key=lambda x: int(x.split()[1]))) for l in lst: i, j, k = l.split() m = int(i[..

프로그래머스 2023.06.01