[Leetcode] 17. Letter Combinations of a Phone Number
·
코딩테스트/Python
🔗 Problem Link Letter Combinations of a Phone Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ❔Thinking 2에서 9까지 숫자가 주어질 때, 각 숫자에 적힌 알파벳으로 가능한 조합을 모두 담은 리스트를 반환한다. 💻Solution 1. 조합을 활용한 풀이 from itertools import product def letterCombinations(self, digits: str) -> List[str]: ..
[Leetcode] 200. Number of Islands
·
코딩테스트/Python
🔗 Problem Link Number of Islands - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ❔Thinking 0은 물, 1은 땅을 나타내는 grid가 주어질 때, 섬의 개수를 반환한다. 💻Solution 1. while을 활용한 DFS 풀이 def numIslands(grid: List[List[str]]) -> int: island = 0 m, n = len(grid), len(grid[0]) for i in range(m): for j in..
[Programmers] Level 2. 행렬 테두리 회전하기
·
코딩테스트/Python
🔗 Problem Link 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ❔Thinking 주어진 직사각형 범위의 테두리를 시계방향으로 회전하고, 이 테두리에서 가장 작은 값들을 출력한다. 💻Solution def solution(rows, columns, queries): answer = [] matrix = [] # 행렬 생성 for i in range(1, rows*columns, columns): tmp = [] for j in range(i, i+columns): tmp.append(j) matrix.append(tmp) # matrix = [[..
[Programmers] Level 3. 가장 먼 노드
·
코딩테스트/Python
🔗 Problem Link 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ❔Thinking 1부터 시작하여 연결된 노드 중 가장 먼 거리의 노드의 개수를 반환한다. 💻Solution from collections import deque def solution(n, edge): graph = [[] for i in range(len(edge)+1)] distance = [-1] * (n+1) # 그래프 연결하기 for e in edge: start, end = e graph[start].append(end) graph[end].append(start) # ..
[Programmers] Level 2. 진료과별 총 예약 횟수 출력하기
·
코딩테스트/MySQL
🔗 Problem Link 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ❔Thinking APPOINTMENT 테이블에서 2022년 05월에 예약한 횟수를 진료과코드별로 출력한다. 💻Solution SELECT MCDP_CD AS '진료과코드', COUNT(APNT_YMD) AS '5월예약건수' FROM APPOINTMENT WHERE SUBSTRING(APNT_YMD, 1, 7) = '2022-05' GROUP BY MCDP_CD ORDER BY `5월예약건수` ASC, `진료과코드` ASC 🗝️keypoint MySQL에서 Alias를 로직에 활용하..
[Programmers] Level 2. 수식 최대화
·
코딩테스트/Python
🔗 Problem Link 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ❔Thinking 주어진 +, -, * 연산자들의 우선순위를 달리하며 수식을 계산했을 때, 그 절댓값이 가장 큰 값을 반환한다. 💻Solution from itertools import permutations def solution(expression): answer = [] used_expression = [] expression_list = [] # 사용된 연산자 종류 구하기 for ex in ['*', '+', '-']: if ex in expression: used_expre..