首页 > TAG信息列表 > leetcode977

leetcode977(双指针)

mycode: class Solution { public: vector<int> sortedSquares(vector<int>& nums) { int n = 100000; int x = 0; for(int i=0;i<nums.size();i++){ if(abs(nums[i])<n){

Leetcode977 有序数组的平方

方法一:先平方,再排序 时间复杂度:O(n+nlogn) => O(nlogn) Python class Solution: def sortedSquares(self, nums: List[int]) -> List[int]: for i in range(len(nums)): nums[i] = nums[i] ** 2 nums.sort() return nums Java class Sol