Algorithm
-
[🥲 프로그래머스] 신고 결과 받기 (2022 KAKAO BLIND RECRUITMENT)Algorithm/1일 1코테 2022. 2. 3. 14:57
신고 결과 받기 https://programmers.co.kr/learn/courses/30/lessons/92334?language=python3 코딩테스트 연습 - 신고 결과 받기 문제 설명 신입사원 무지는 게시판 불량 이용자를 신고하고 처리 결과를 메일로 발송하는 시스템을 개발하려 합니다. 무지가 개발하려는 시스템은 다음과 같습니다. 각 유저는 한 번에 한 명의 programmers.co.kr 오랜만에 코테.... 몇개월 안풀었다고 다 까먹음 ㅎ^^ 1단계지만 광탈했다! 유저가 신고한 사람들 중 k번 이상 신고당한 사람들을 추출하면 되는 문제! # 다른 사람 풀이 # 다른 사람 코드 참고 def solution(id_list, report, k): answer = [0] * len(id_list) ..
-
[😍 프로그래머스] 튜플 (2019 카카오 개발자 겨울 인턴십)Algorithm/1일 1코테 2021. 8. 26. 23:43
https://programmers.co.kr/learn/courses/30/lessons/64065 코딩테스트 연습 - 튜플 "{{2},{2,1},{2,1,3},{2,1,3,4}}" [2, 1, 3, 4] "{{1,2,3},{2,1},{1,2,4,3},{2}}" [2, 1, 3, 4] "{{4,2,3},{3},{2,3,4,1},{2,3}}" [3, 2, 4, 1] programmers.co.kr 🏐 나의 풀이 🏐 from collections import Counter def solution(s): s= s.replace('{','') # 괄호 제거 s= s.replace('}','') s = list(map(int, s.split(','))) # ,으로 숫자 구분 number_dict = Counte..
-
[😍 프로그래머스] 단속카메라 - greedyAlgorithm/1일 1코테 2021. 8. 22. 12:56
https://programmers.co.kr/learn/courses/30/lessons/42884 코딩테스트 연습 - 단속카메라 [[-20,15], [-14,-5], [-18,-13], [-5,-3]] 2 programmers.co.kr 🍪 나의 풀이 def solution(routes): routes.sort(key=lambda x:x[0], reverse=True) # 시작점이 가장 큰 숫자부터 정렬 # [[-5, -3], [-14, -5], [-18, -13], [-20, 15]] count = 0 # 결과 camera = float('inf') # 카메라 위치는 임의로 가장 큰 숫자로 지정 for i in range(len(routes)): if routes[i][0]
-
[leetcode] 78. subsets (python)Algorithm/1일 1코테 2021. 8. 19. 13:51
리트코드 78번 문제 https://leetcode.com/problems/subsets/submissions/ Subsets - 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 내가 푼 풀이 class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: answer = [[]] # 빈 값을 미리 넣어줌 for i in range(1, len(nums)+1): number_group = list(it..
-
[leetcode] 그리디 알고리즘 모음집.zipAlgorithm/1일 1코테 2021. 8. 14. 21:51
그리기 알고리즘의 핵심은 그때그때 가장 적합한 선택을 하는 것! 122번. 주식 팔고사기 가장 적합한 선택 -> 바로 다음 값이 오르면 팔고, 아니면 만다! class Solution: def maxProfit(self, prices: List[int]) -> int: result = 0 # 결과 저장 for i in range(len(prices)-1): if prices[i+1]>prices[i]: # 다음 값이 크면 판다! result += prices[i+1]-prices[i] return result 406번. 키에 따라 재정렬 가장 적합한 선택 -> 키(역순)/인덱스 순으로 정렬한 뒤 인덱스대로 삽입 class Solution: def reconstructQueue(self, people: L..
-
[백준] 4796번 캠핑 - 그리디 알고리즘Algorithm/1일 1코테 2021. 8. 11. 18:37
https://www.acmicpc.net/status?user_id=kimdi96&problem_id=4796&from_mine=1 채점 현황 www.acmicpc.net 처음 단순하게 생각한 답....! 그런데 찾아보니 예외가 있더라 for i in range(1,999): L,P,V = map(int, input().split()) if L == 0 and P == 0 and V == 0: break answer= (V//P)*L + (V%P) print("Case", i, ":", answer) 예외처리를 해줬다! for i in range(1,999): L,P,V = map(int, input().split()) if L == 0 and P == 0 and V == 0: break answer=..
-
[🥲 프로그래머스] 섬 연결하기 - 그리디 알고리즘Algorithm/1일 1코테 2021. 8. 10. 23:02
https://programmers.co.kr/learn/courses/30/lessons/42861 코딩테스트 연습 - 섬 연결하기 4 [[0,1,1],[0,2,2],[1,2,5],[1,3,1],[2,3,8]] 4 programmers.co.kr 나의 풀이 def solution(n, costs): costs.sort(key=lambda x:x[2]) # 비용이 작은 순대로 정렬 all_island = [i for i in range(n)] # 모든 섬 answer = 0 now = costs.pop(0) # 맨 처음 costs를 뺀다 while all_island: cur_island = now[0] # 현재섬 next_island = now[1] # 다음섬 answer += now[2] # 비용 답..
-
[🥲 프로그래머스] 단어 변환 - BFS/DFSAlgorithm/1일 1코테 2021. 8. 2. 22:23
https://programmers.co.kr/learn/courses/30/lessons/43163 코딩테스트 연습 - 단어 변환 두 개의 단어 begin, target과 단어의 집합 words가 있습니다. 아래와 같은 규칙을 이용하여 begin에서 target으로 변환하는 가장 짧은 변환 과정을 찾으려고 합니다. 1. 한 번에 한 개의 알파벳만 바꿀 수 programmers.co.kr ✅ 내가 시도한 풀이 from collections import deque def solution(begin, target, words): # 그래프 생성 words.append(begin) graph = {i:[] for i in words} for i in range(len(words)-1): for j in ran..