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
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..

article thumbnail
567. Permutation in String
Algorithm 2021. 10. 2. 14:03

Permutation in String - 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 영문 소문자로 구성된 문자열 s1, s2가 주어진다. s1의 순열 문자열을 s2가 포함하고 있는지 유무를 반환하는 문제다. 순열 문자열은 어떤 문자열 s1을 구성하는 문자의 순서를 변경해서 만들어지는 새로운 문자열을 의미한다. 예시 Input: s1 = "ab", s2 = "eidbaooo" Output: true Explanation: s2 contains one perm..