Algorithm/1일 1코테
-
[😍 프로그래머스] 단속카메라 - 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..
-
[🥲 프로그래머스] 네트워크 - BFS/DFSAlgorithm/1일 1코테 2021. 7. 28. 20:40
https://programmers.co.kr/learn/courses/30/lessons/43162?language=python3 코딩테스트 연습 - 네트워크 네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있 programmers.co.kr ✅ 내가 푼 풀이 # 1차시도 -> 92.3점 def solution(n, computers): graph = {i:[] for i in range(n)} stack = [1] visited = [] # 그래프 형식으로 생성 for net in range(len(computers)): for num in range(len(co..
-
[프로그래머스] 입국심사 - 이분탐색Algorithm/1일 1코테 2021. 7. 26. 15:26
https://programmers.co.kr/learn/courses/30/lessons/43238?language=python3 코딩테스트 연습 - 입국심사 n명이 입국심사를 위해 줄을 서서 기다리고 있습니다. 각 입국심사대에 있는 심사관마다 심사하는데 걸리는 시간은 다릅니다. 처음에 모든 심사대는 비어있습니다. 한 심사대에서는 동시에 한 programmers.co.kr 다른 사람 풀이 def solution(n, times): answer = 0 left = 0 right = max(times) * n # 최대 시간 while left < right: total = 0 # 심사한 인원수 mid = (left+right) // 2 # 현재 시간 # mid만큼의 시간이 있을때 처리할 수 있는 인원 수 ..