Skip to main content
edited title
Link
toolic
  • 15.7k
  • 5
  • 29
  • 216

LeetCode 977: SquareSquares of a sorted array, maintaining nondecreasingnon-decreasing order

Became Hot Network Question
added 2 characters in body
Source Link
toolic
  • 15.7k
  • 5
  • 29
  • 216

I tried solving the leetcodeLeetCode question like many others, trying to incorporate the O(n) time complexity requirement.

by manually calculating the time cost (and also the aiAI tool by LeetCode) I. I seem to get O(n) time complexity, but this code is incredibly slow. Is it due to the 'chunkiness' of it or something else.? Feel free to point out any redundancies or inefficient lines.

I tried solving the leetcode question like many others, trying to incorporate the O(n) time complexity requirement.

by manually calculating the time cost (and also the ai tool by LeetCode) I seem to get O(n) time complexity, but this code is incredibly slow. Is it due to the 'chunkiness' of it or something else. Feel free to point out any redundancies or inefficient lines.

I tried solving the LeetCode question like many others, trying to incorporate the O(n) time complexity requirement.

by manually calculating the time cost (and also the AI tool by LeetCode). I seem to get O(n) time complexity, but this code is incredibly slow. Is it due to the 'chunkiness' of it or something else? Feel free to point out any redundancies or inefficient lines.

cite the problem definition
Source Link
J_H
  • 42.1k
  • 3
  • 38
  • 157

I tried solving the leetcode questionquestion like many others, trying to incorporate the O(n) time complexity requirement.

  1. Squares of a Sorted Array

Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

Example

  • Input: nums = [-4,-1,0,3,10]
  • Output: [0,1,9,16,100]
  • Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, it becomes [0,1,9,16,100].

I came up with the following:

I tried solving the leetcode question like many others, trying to incorporate the O(n) time complexity. I came up with the following:

I tried solving the leetcode question like many others, trying to incorporate the O(n) time complexity requirement.

  1. Squares of a Sorted Array

Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

Example

  • Input: nums = [-4,-1,0,3,10]
  • Output: [0,1,9,16,100]
  • Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, it becomes [0,1,9,16,100].

I came up with the following:

added 2 characters in body; edited tags; edited title
Source Link
toolic
  • 15.7k
  • 5
  • 29
  • 216
Loading
edited tags
Link
Loading
formatting
Source Link
Ben A
  • 10.8k
  • 5
  • 38
  • 103
Loading
Source Link
Loading