목록전체 글 (1208)
넘치게 채우기
https://leetcode.com/problems/insert-interval/description/ Leetcode - Insert Interval 문제 유형 : 배열, 구현 문제 난이도 : Medium 문제 You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the ith interval and intervals is sorted in ascending order by starti. You are also given an interval newInterval = [start, end] that represents ..
https://leetcode.com/problems/contiguous-array/description/ Leetcode - Contiguous Array 문제 유형 : 부분합, 해시 문제 난이도 : Medium 문제 Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1. 바이너리 배열 nums가 주어진다. 0과 1의 개수가 같은 부분배열의 최대 길이를 구하시오. 풀이 부분합을 이용하여 풀 수 있다. 해시맵을 만들어서 총합-인덱스의 형태로 저장한다. 배열을 순회하면서, 총합에 0이면 -1을, 1이면 1을 추가한다. 만약 총합이 0이라면, 처음부터 i인덱스까지 조..
https://leetcode.com/problems/find-the-pivot-integer/description/ Leetcode - Find the Pivot Integer 문제 유형 : 수학 문제 난이도 : Easy 문제 Given a positive integer n, find the pivot integer x such that: The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively. Return the pivot integer x. If no such integer exists, return -1. It is guaranteed that there ..
https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list/description/ Leetcode - Remove Zero Sum Consecutive Nodes from Linked List 문제 유형 : 연결리스트, 재귀 문제 난이도 : Medium 문제 Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences. After doing so, return the head of the final linked list. You may retur..
https://leetcode.com/problems/custom-sort-string/description/ Leetcode - Custom Sort String 문제 유형 : 문자열 처리, 정렬, 그리디 문제 난이도 : Medium 문제 You are given two strings order and s. All the characters of order are unique and were sorted in some custom order previously. Permute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a char..
만일 m이 a-b를 나눌 때, a와 b가 모듈러 m에 대해 합동이다. 특히, a를 m으로 나눈 나머지가 r이면, a와 r는 모듈러 m에 대해 합동이다. 이떄, 나머지 r은 0 = 1이고 gcd(a, m) = g를 만족한다고 하자. 만일 g !| b이면, 합동방정식 은 해를 가지지 않는다. 만일 g | b이면, 합동방정식 정확히 g개의 서로 다른 해를 가진다. 모든 해를 찾으려면, 우선 일차방정식 au + mv = g의 해 (u0, v0)을 찾는다. x0 = cu/g가 의 해가 되고, 모든 합동이 아닌 해는 과 같이 나타낼 수 있다. 주의 선형 합동방정식 정리에서 가장 중요한 경우는 gcd(a, m) = 1인 경우이다. 이 경우, 합동방정식은 단 하나의 해를 가진다. 고차 합동방정식 고차 합동방정식도 수론..
https://leetcode.com/problems/intersection-of-two-arrays/description/ Leetcode - Intersection of Two Arrays 문제 유형 : 해시, 그리디 문제 난이도 : Easy 문제 Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order. 두 정수배열 nums1과 nums2가 주어진다. 교차점을 반환하시오. 결과의 각 요소는 값이 겹치면 안되고, 순서는 상관없습니다. 풀이 해시맵에 nums1의 요소..
2 이상의 정수 p의 약수가 1과 p 뿐일 때, p를 소수(prime number)라고 부른다. 2 이상의 소수가 아닌 수를 합성수(composite number)라고 부른다. 소수 p가 곱 ab를 나눈다고 가정하자. 그러면 p는 a를 나누거나, b를 나눈다. (또는 a와 b 모두 나눈다.) 증명) p가 곱 ab를 나눈다고 하자. 만일 p가 a를 나눈다면 증명이 끝나므로, 나누지 않는다고 가정하면, gcd(p, a)가 어떤 수인지 생각해야 한다. 이 수는 p를 나누므로, 1 또는 p이다. p가 a를 나누지 않으므로, p는 1이다. 6장의 정리를 이용하여, px + ay = 1에서 양변에 b를 곱한다. pbx + aby = b pbx는 p로 나누어지고, p가 ab를 나누므로, aby 역시 p로 나누어진다...
https://leetcode.com/problems/minimum-common-value/description/ Leetcode - Minimum Common Value 문제 유형 : 그리디, 투포인터 문제 난이도 : Easy 문제 Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1. Note that an integer is said to be common to nums1 and nums2 if both arrays h..
두 개의 정수 a, b가 주어졌을 때, a의 배수와 b의 배수로 만들 수 있는 수를 모두 찾아보자. 다시말해, ax + by에서 x와 y에 대입해 만들 수 있는 수를 찾아보자. a=42, b = 30으로 해보자. x = -3 x = -2 x = -1 x = 0 x = 1 x = 2 x = 3 y = -3 -216 -174 -132 -90 -48 -6 36 y = -2 -186 -144 -102 -60 -18 24 66 y = -1 -156 -114 -72 -30 12 54 96 0 -126 -84 -42 0 42 84 126 y = 1 -96 -54 -12 30 72 114 156 y = 2 -66 -24 18 60 102 144 186 y = 3 -36 6 48 90 132 174 216 표의 수들이 ..