avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

977.Orderly array square

  2024-01-01        
字数统计: 164字   |   阅读时长: 1min

topic:

Press you Non -reduced order Sorting integer array nums,return Each number square New array of composition,The request is also pressed Non -reduced order Sort。

 

Exemplary example 1:

enter:nums = [-4,-1,0,3,10]
Output:[0,1,9,16,100]
explain:After,Array becomes [16,1,0,9,100]
Sort后,Array becomes [0,1,9,16,100]

Exemplary example 2:

enter:nums = [-7,-3,2,3,11]
Output:[4,9,9,49,121]

 

hint:

  • 1 <= nums.length <= 104
  • -104 <= nums[i] <= 104
  • nums Pressed Non -reduced order Sort

 

Advance:

  • PleaseDesign time complexity is O(n) The algorithm solves this problem
Related Topics
  • Array
  • Double pointer
  • Sort

  • 👍 777
  • 👎 0
  • [977.Orderly array square.md]()

    Thought:

    I originally planned to write an insertion after each calculation was calculated,The result is timeout。IgnoresortPuzzle。

    Code:

    1
    2
    3
    4
    5
    6
    7
    class Solution:
    def sortedSquares(self, nums: List[int]) -> List[int]:
    nu = []
    for i in nums:
    nu.append(i * i)
    nu.sort()
    return nu
    • Python
    • answer

    扫一扫,分享到微信

    微信分享二维码
    Python beat98.40% collectionsofCounter method!
    Sword finger Offer 43. 1~n Integer 1 Number of times
    目录
    1. 1. topic:
    2. 2. Thought:
    3. 3. Code:

    150 篇 | 131.7k
    次 | 人
    这里自动载入天数这里自动载入时分秒
    2022-2025 loong loong | 新南威尔士龙龙号