https://school.programmers.co.kr/learn/courses/30/lessons/131123 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr GROUP BY 사용SELECT food_type, rest_id, rest_name, favoritesFROM rest_infoWHERE (food_type,favorites) IN( SELECT food_type, MAX(FAVORITES) FROM rest_info GROUP BY food_type)ORDER BY food_type DESC; RANK() 활용# REST_INFO 테이블에서 음식종류별로 즐겨찾기수가 가장 많은 식..
https://school.programmers.co.kr/learn/courses/30/lessons/86971 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr # 25년 10월 30일 목요일edge=[]visited=[]cnt=0def dfs(cur,a,b): # (cur, except1, except2) global cnt visited[cur]=True for next in edge[cur]: if (next==a and cur==b) or (next==b and cur==a): # skip edge (a,b) or (b,a) continue ..
https://leetcode.com/problems/product-sales-analysis-iii/ WITH tmp AS( SELECT *, rank() OVER(PARTITION BY product_id ORDER BY year) myRank FROM sales)SELECT product_id, year first_year, quantity, priceFROM tmpWHERE myRank=1;RANK() 윈도우 함수를 이용하여 풀이했다.product_id별로, year에 대해 rank를 부여하여 rank=1인 것을 select 하도록 했다.요즘은 윈도우 함수를 활용할 수 있으면 해당 풀이를 선호하는 것 같다... 서브 쿼리보다 간결해서 좋은 것 같다. 서브쿼리 ver.SELECT..
https://school.programmers.co.kr/learn/courses/30/lessons/43164 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr # 25년 10월 22일 수요일 20:50import copyfrom collections import defaultdictanswer=[]tmpAnswer=[]myDict=defaultdict(list)l=0def dfs(cur): global answer,tmpAnswer,myDict,l if len(tmpAnswer)==l: # if visited all country, if answer: if answe..
https://leetcode.com/problems/tree-node/ 내 코드# 25년 10월 20일 월요일 21:08# p_id가 null: Root# p_id에 없는 놈들: LeafWITH tb_leaf AS( SELECT id FROM tree WHERE id NOT IN( SELECT p_id FROM tree WHERE p_id IS NOT NULL ))SELECT id, CASE WHEN p_id IS NULL THEN "Root" WHEN id IN (SELECT id FROM tb_leaf) THEN "Leaf" ELSE "Inner" END typeFROM tree;
https://school.programmers.co.kr/learn/courses/30/lessons/42584 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 정답 코드# 25년 10월 15일 수요일 21:54def solution(prices): n=len(prices) # 10^4 answer=[0]*n stack=[] # (인덱스, 값) for i in range(n): while stack and stack[-1][1]>prices[i]: index,value=stack.pop() answer[index]=i-ind..