题目要求

Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order.

题目分析及思路

题目给出一个整数数组,已经按照非减顺序排列好了。要求返回一个数组,包含的元素是已知数组元素的平方,且按照非减顺序排列。可以使用列表的sort()函数进行排序。

python代码​

class Solution:

def sortedSquares(self, A):

"""

:type A: List[int]

:rtype: List[int]

"""

B = list()

for i in A:

B.append(i**2)

B.sort()

return B

LeetCode 977 Squares of a Sorted Array 解题报告的更多相关文章

  1. 【LeetCode】977. Squares of a Sorted Array 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcod ...

  2. #Leetcode# 977. Squares of a Sorted Array

    https://leetcode.com/problems/squares-of-a-sorted-array/ Given an array of integers A sorted in non- ...

  3. LeetCode 977. Squares of a Sorted Array (有序数组的平方)

    题目标签:Array 题目给了我们一组 从小到大的 integers,让我们平方数字 并且 也排序成 从小到达. 因为有负数在里面,平方后,负数在array的位置会变动. 可以设left 和 righ ...

  4. 【Leetcode_easy】977. Squares of a Sorted Array

    problem 977. Squares of a Sorted Array solution: class Solution { public: vector<int> sortedSq ...

  5. 【LeetCode】153. Find Minimum in Rotated Sorted Array 解题报告(Python)

    [LeetCode]153. Find Minimum in Rotated Sorted Array 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode. ...

  6. 【LeetCode】697. Degree of an Array 解题报告

    [LeetCode]697. Degree of an Array 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/degree- ...

  7. LeetCode: Search in Rotated Sorted Array 解题报告

    Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you before ...

  8. LeetCode 新题: Find Minimum in Rotated Sorted Array 解题报告-二分法模板解法

    Find Minimum in Rotated Sorted Array Question Solution Suppose a sorted array is rotated at some piv ...

  9. 【LeetCode】Find Minimum in Rotated Sorted Array 解题报告

    今天看到LeetCode OJ题目下方多了"Show Tags"功能.我觉着挺好,方便刚開始学习的人分类练习.同一时候也是解题时的思路提示. [题目] Suppose a sort ...

随机推荐

  1. [转]在Windows上安装RabbitMQ

    原文链接    翻译:xiezc 下载服务器 描述 下载   Windows系统安装程序(来自Bintray) 的RabbitMQ的服务器-3.7.4.exe (签名) Windows系统安装程序(来 ...

  2. Thrift 源码学习一——源码结构

    Thrift 客户端与服务端的交互图 源码结构 传输层 TTransport: TTransport:客户端传输层抽象基础类,read.write.flush.close 等方法 TSocket 与 ...

  3. Java多线程的同步机制(synchronized)

    一段synchronized的代码被一个线程执行之前,他要先拿到执行这段代码的权限,在 java里边就是拿到某个同步对象的锁(一个对象只有一把锁): 如果这个时候同步对象的锁被其他线程拿走了,他(这个 ...

  4. mysql5.7.20安装

    MySQL 的官网下载地址:http://www.mysql.com/downloads/ 一.各版本的区别 1. MySQL Community Server 社区版本,开源免费,但不提供官方技术支 ...

  5. Unity5 AssetBundle系列——简单的AssetBundleManager

    一个AssetBundle同时只能加载一次,所以实际使用中一般会伴随着AssetBundle包的管理. 下面是一个简单的AssetBundle管理器,提供了同步和异步加载函数: using Unity ...

  6. 【转】WPF自定义控件与样式(4)-CheckBox/RadioButton自定义样式

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等 本文主要内容: CheckBox复选框的自定义样式,有两种不同的风格实现: RadioB ...

  7. 【转】WPF自定义控件与样式(3)-TextBox & RichTextBox & PasswordBox样式、水印、Label标签、功能扩展

    一.前言.预览 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等. 本文主要是对文本输入控件进行样式开发,及相关扩展功能开发,主要内容包括: 基本文 ...

  8. java主线程等待所有子线程执行完毕在执行(常见面试题)

    java主线程等待所有子线程执行完毕在执行(常见面试题) java主线程等待所有子线程执行完毕在执行,这个需求其实我们在工作中经常会用到,比如用户下单一个产品,后台会做一系列的处理,为了提高效率,每个 ...

  9. 【Window 7】解决Win7远程桌面无法全屏的方法

    在Windows中有一项远程桌面功能,可以登录到其他电脑上进行远程控制,就像操纵本机一样,非常方便.但是最近发现用远程桌面登录过去时并不是全屏模式,而是窗口模式,老要拉滚动条,实在很不方便,今天还是到 ...

  10. python 带正则的search 模块

    glob  是python 提供的一个支持正则表达式的查找文件的模块. 实现上采用了os.listdir() 和 fnmatch.fnmatch().  但是没有真的invoking a subshe ...