977. Squares of a Sorted Array
https://leetcode.com/problems/squares-of-a-sorted-array/
给定整数数组的按平方值排序。暴力法O(NlgN),进一步优化=>O(N)。负数范围是一个排好序的序列,正数同样,每步都是按序从它们中各自最小或最大的选一个,因此用两个指针指向数组两边,每次选大的倒着插入到res。
Last updated
Was this helpful?
https://leetcode.com/problems/squares-of-a-sorted-array/
给定整数数组的按平方值排序。暴力法O(NlgN),进一步优化=>O(N)。负数范围是一个排好序的序列,正数同样,每步都是按序从它们中各自最小或最大的选一个,因此用两个指针指向数组两边,每次选大的倒着插入到res。
Last updated
Was this helpful?