A headline algorithm problem, an unknown solution!

subject Enter the integer array arr to find the minimum number of k. For example, if you enter 8 numbers: 4, 5, 1, 6, 2, 7, 3 and 8, the smallest 4 numbers are 1, 2, 3 and 4. Example 1: Input: arr = [3,2,1], k = 2 output: [1,2] or [2,1] example 2: Input: arr = [0,1,2,1], k = 1, output: [0] Restrictions: 0 <= k <= arr.length &l ...

Posted by thinfile on Sat, 19 Feb 2022 09:37:24 +0100

Day86 sliding window maximum

Give you an integer array nums, with a sliding window of size k moving from the leftmost side of the array to the rightmost side of the array. You can only see k numbers in the sliding window. The sliding window moves only one bit to the right at a time. Returns the maximum value in the sliding window https://leetcode-cn.com/problems/sliding-w ...

Posted by jokeruk on Sat, 19 Feb 2022 08:43:14 +0100

Monotone stack application

As the name suggests, a monotone stack is a stack with monotone properties Analog monotone stack Array: 4, 5, 2, 6, 3 Monotonically increasing stack (the top of the stack is smaller than the bottom of the stack. When the element is put into the stack, if it meets the monotonicity, it will be put into the stack. If it does not meet the monoto ...

Posted by DanArosa on Sat, 19 Feb 2022 06:42:58 +0100

LeetCode-004 Median of Two Sorted Arrays

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example: Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Explanation: merged array = [1,2,3] and median is 2. Solution 1 To find the median in an ordered array, you ...

Posted by theorok on Sat, 19 Feb 2022 05:09:39 +0100

C + + octet sharing - data structure II - hash table

C + + octet sharing - data structure II - hash table preface What is a hash table? The search Binary Tree finds the value by comparing it with the target value one by one from the root node, and then looking down until the target value is found or the root node is not found. The time complexity is O (log n). In the hash table, the value and ...

Posted by argrafic on Sat, 19 Feb 2022 02:43:16 +0100

Record of sword finger offer

Record of sword finger offer (1) (February 18, 2022) Write in the front: I haven't learned c + +. Refer to the problem-solving comments and learn while brushing the questions. data structure Print linked list from end to end describe Enter the head node of a linked list and return the value of each node in the order from the end to the h ...

Posted by ursvmg on Sat, 19 Feb 2022 02:34:01 +0100

Force buckle -- design cycle queue (problem solution)

This problem needs to implement a circular queue, so before that, we need to know the concept and structure of queue Queue: a special linear table that can only be inserted at one end and deleted at the other end. It has the characteristics of first in first out, then in and then out Delete one end of the queue Enter the queue: the end of t ...

Posted by trygve on Sat, 19 Feb 2022 01:32:12 +0100

Solution to 2021 TIANTI competition

2021 program design TIANTI competition was held on April 24. This article is part of the solution of TIANTI competition. Some problems did not get full marks at that time. Because the school opened the reproduction competition of TIANTI competition, write again. Note: the answer in this article is not the standard answer. The score of each que ...

Posted by devans on Sat, 19 Feb 2022 00:34:08 +0100

Data structure - sort

1 bubble sort 1. The data to be sorted can be in array or linked list 2. Exchange only when strictly unequal, that is, when equal, do not exchange, which shows that the algorithm is stable Pseudo code void Bubble_Sort(ElementType A[], int N) { for (p = N - 1; p > 0; p--) { flag = 0; for (i = 0; i < p; i++) { if (A[i] &gt ...

Posted by christh on Fri, 18 Feb 2022 18:59:03 +0100

05 bucket sort, count sort and cardinality sort of sorting operation

Because the time complexity of bucket sorting, counting sorting and cardinal sorting is o(n) linear, these three sorting methods belong to linear sorting. The principles of these three algorithms are not difficult, and the analysis of time complexity and space complexity is relatively simple, so we will focus on the applicable scenarios of the ...

Posted by Misticx on Fri, 18 Feb 2022 14:48:23 +0100