2. Insertion Sort, 将arr分为左边(sorted array)和右边(unsorted array),然后依次将unsorted array的元素insert到sorted array里面。 T: O(n ^ 2), S: O(1) 同样的思路[LeetCode] 147. Insertion Sort List_Middle tag: Linked List 3. Merge Sort, 将array 分成两半,然后在merge两个sorted array, 每次...
[LeetCode] 1636. Sort Array by Increasing Frequency Given an array of integersnums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order. Return thesorted array. Example 1: Input: nums = [1,1,2...
package leetcode func sortArrayByParityII(A []int) []int { if len(A) == 0 || len(A)%2 != 0 { return []int{} } res := make([]int, len(A)) oddIndex := 1 evenIndex := 0 for i := 0; i < len(A); i++ { if A[i]%2 == 0 { res[evenIndex] = A[i] even...
Given an array nums with n objects colored red, white, or blue, sort themin-placeso that objects of the same color are adjacent, with the colorsin the order red, white, and blue. We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively. 说...
classSolution:defheightChecker(self,heights:List[int])->int:z=0fork,vinenumerate(sorted(heights)):ifv!=heights[k]:z+=1returnz 977. 有序数组的平方 给定一个按非递减顺序排序的整数数组A,返回每个数字的平方组成的新数组,要求也按非递减顺序排序。
The values at even indices 0 and 2 are sorted in non-decreasing order. Return the array formed after rearranging the values of nums. Example 1: Input: nums = [4,1,2,3] Output: [2,3,4,1] Explanation: First, we sort the values present at odd indices (1 and 3) in non-increasing...
之前在leetcode刷题的时候遇到这道题(题目来源寻找两个有序数组的中位数) 给定两个大小为 m 和 n 的有序数组 nums1 和 nums2。 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n))。 你可以假设 nums1 和 nums2 不会同时为空。
Example 1: Input:s = "lEetcOde"Output:"lEOtcede"Explanation:'E', 'O', and 'e' are the vowels in s; 'l', 't', 'c', and 'd' are all consonants. The vowels are sorted according to their ASCII values, and the consonants remain in the same places. ...
[2089. 找出数组排序后的目标下标](https://leetcode.cn/problems/find-target-indices-after-sorting-array/) [2094. 找出 3 位偶数](https://leetcode.cn/problems/finding-3-digit-even-numbers/) [2099. 找到和最大的长度为 K 的子序列](https://leetcode.cn/problems/find-subsequence-of-length-k-...
Problem 1: Find All Numbers Disappeared in an Array Problem 2: Find the Duplicate Number6. In-place Reversal of Linked ListProblem 1: Reverse Linked List Problem 2: Reverse Nodes in k-Group7. Tree BFSProblem 1: Binary Tree Level Order Traversal Problem 2: Binary Tree Zigzag Level Order ...