본문 바로가기

Data Engineering/Python14

[코테] 프로그래머스 - 삼각 달팽이 Python 코드 def solution(n): answer = [] for i in range(1, n+1): arr = [0]*i answer.append(arr) i, j, num, nn = -1, 0, 0, n arrow = 0 # 0: 아래, 1: 오른쪽, 2: 왼쪽위 for x in range(0, n): # 0 부터 n-1 까지 반복 for y in range(nn, 0, -1): # n번, n-1번, n-2번 .. 1번 num += 1 if arrow == 0: i += 1 elif arrow == 1: .. 2025. 10. 15.
[코테] 프로그래머스 - 시소 짝꿍 Python 코드 from collections import Counterdef solution(weights): answer = 0 weights.sort() counter = Counter(weights) for (w, c) in counter.items(): answer += c * (c-1) // 2 # 1:1 answer += c * counter[w*2] # 2:1 answer += c * counter[w*3/2] # 3:2 answer += c * counter[w*4/3] # 4:3 return answer # https://school.programmers.co.kr/learn/courses.. 2025. 10. 15.
[코테] 프로그래머스 - 가장 큰 수 Python 코드 123456789101112131415161718192021from functools import cmp_to_key def solution(numbers): strNums = map(str, numbers) strNums = sorted(strNums, key=cmp_to_key(compare)) return ''.join(strNums) if strNums[0] != '0' else '0' def compare(strNum1, strNum2): num1 = strNum1 + strNum2 num2 = strNum2 + strNum1 if num1 num2: return 1 elif num2 num1: return -1 else:.. 2025. 9. 18.
[코테] 프로그래머스 - 더 맵게 Python 코드 1234567891011121314151617181920212223import heapq def solution(scoville, K): answer = 0 heapq.heapify(scoville) while True: min1 = heapq.heappop(scoville) if min1 >= K: break elif len(scoville) == 0: answer = -1 break min2 = heapq.heappop(scoville) new_scoville = min1 + 2*min2 heapq.heappush(scoville, new.. 2025. 9. 18.