Zero to Hero
article thumbnail
986. Interval List Intersections
Algorithm 2021. 10. 14. 09:55

Interval List Intersections - 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 구간 정보를 담은 2개의 list가 주어진다. 두 list에 담긴 구간 정보를 비교해서 겹치는 구간의 시작과 끝 정보를 담아 반환하는 문제다. 예시 firstList = [[0,2],[5,10],[13,23],[24,25]] secondList = [[1,5],[8,12],[15,24],[25,26]] Output: [[1,2],[5,5],[8,10],[15,23..

article thumbnail
74. Search a 2D Matrix
Algorithm 2021. 10. 11. 13:40

Search a 2D Matrix - 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 row, col이 커질수록 큰 값이 들어있는 2차원 배열에서 특정 값이 있는지 탐색하는 문제다. 1. 이진 탐색 240. Search a 2D Matrix II Search a 2D Matrix II - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your ..

article thumbnail
33. Search in Rotated Sorted Array
Algorithm 2021. 10. 11. 13:29

Search in Rotated Sorted Array - 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 정렬된 임의의 정수로 구성된 list의 특정 index 기준으로 반으로 잘라 만들어진 두 개의 list a, b를 거꾸로 붙인 list가 주어진다. 이 list에서 특정 값이 존재하는지를 판단해 존재한다면 그 인덱스를 반환하고 없다면 -1을 반환한다. 단 시간 복잡도는 log(N)으로 해결한다. 예시 Input: nums = [4,5,6,7,0,1,2], t..

article thumbnail
34. Find First and Last Position of Element in Sorted Array
Algorithm 2021. 10. 11. 11:14

Find First and Last Position of Element in Sorted Array - 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 오름차순으로 정렬된 1차원 list와 정수 target이 주어진다. 주어진 list에서 target이 존재하는 범위의 시작과 끝 인덱스 값을 반환하는 문제다. 만일 target이 list 안에 존재하지 않는다면 [-1, -1]을 반환한다. 예시 Input: nums = [5,7,7,8,8,10], target = ..

article thumbnail
타겟 넘버
Algorithm 2021. 10. 7. 23:32

코딩테스트 연습 - 타겟 넘버 n개의 음이 아닌 정수가 있습니다. 이 수를 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수 있습니다. -1+1+1+1+1 = 3 +1-1+1+1+ programmers.co.kr 반올림 2년 전 코드 def solution(list1, target): stack1=[(1,list1[0])] visited1=[] length=len(list1) while stack1: item=stack1.pop() if item[0]==length: visited1.append(item) if item[0]

article thumbnail
2477번: 참외밭
Algorithm 2021. 10. 5. 22:26

2477번: 참외밭 첫 번째 줄에 1m2의 넓이에 자라는 참외의 개수를 나타내는 양의 정수 K (1 ≤ K ≤ 20)가 주어진다. 참외밭을 나타내는 육각형의 임의의 한 꼭짓점에서 출발하여 반시계방향으로 둘레를 돌면서 지 www.acmicpc.net import sys r = sys.stdin.readline target = int(r()) x, y, i1, i2 = 0, 0, 0, 0 list1 = [] for i in range(6): direction, length = map(int, r().split()) list1.append((direction, length)) if direction in [3, 4] and y < list1[i][1]: y = list1[i][1] i2 = i if direc..