본문 바로가기

분류 전체보기

(92)
Dual pivot quick sort #include using namespace std;void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp;}void partition(int arr[], int start, int end, int *lp, int *rp) { if (arr[start] > arr[end]) { swap(&arr[start], &arr[end]); } int i = start + 1; int j = end - 1; int k = start + 1; while (k arr[end]) { while (arr[j] > arr[end] && j > k) { j--; } swap(&arr[k], &arr[j]); ..
1679. Max Number of K-Sum Pairs You are given an integer array nums and an integer k.In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.Return the maximum number of operations you can perform on the array. Example 1:Input: nums = [1,2,3,4], k = 5Output: 2Explanation: Starting with nums = [1,2,3,4]:- Remove numbers 1 and 4, then nums = [2,3]- Remove numbers 2 and 3, then ..
11. Container With Most Water You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).Find two lines that together with the x-axis form a container, such that the container contains the most water.Return the maximum amount of water a container can store.Notice that you may not slant the container. Example 1:Input: height = [..
1732. Find the Highest Altitude There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0.You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i​​​​​​ and i + 1 for all (0  the highest altitude of a point. Example 1:Input: gain = [-5,1,5,0,-7]Output: 1Explanation: The altitu..
643. Maximum Average Subarray I You are given an integer array nums consisting of n elements, and an integer k.Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10-5 will be accepted. Example 1:Input: nums = [1,12,-5,-6,50,3], k = 4Output: 12.75000Explanation: Maximum average is (12 - 5 - 6 + 50) / 4 = 51 / 4 = 12.75Exam..
2215. Find the Difference of Two Arrays https://leetcode.com/problems/find-the-difference-of-two-arrays/description/?envType=study-plan-v2&envId=leetcode-75 Given two 0-indexed integer arrays nums1 and nums2, return a list answerof size 2 where:answer[0] is a list of all distinct integers in nums1 which are notpresent in nums2.answer[1] is a list of all distinct integers in nums2 which are notpresent in nums1.Note that the integers in..
디펜스게임 맵 사방으로 한칸씩 확장하는 알고리즘 #include #include #include #include #define MAX_MAP_SIZE 128 // 무조건 짝수, 최소 6 #define weighted_num 0 // 가중치 0~1 실수 using namespace std; /* 0 - left 1 - top 2 - right 3 - bottom 사분면 0 1 2 3 */ class map { private: bool map_array[MAX_MAP_SIZE][MAX_MAP_SIZE]; // true = 길 int start_point[3]; // 시작포인터 [0]=x,[1]=y,[2]=direction (주의: 길 끝을 나타내는 것임(길 끝 다음 블럭이 아님)) int end_point[3]; // end포인터 [0]=x,[1]=y,[..
honer 알고리즘 #include using namespace std; int main(void) { int n; int temp; int sum = 0; int x; int val[1000]; cout > n; for (int i = 0; i