【leetcode】977. Squares of a Sorted Array
题目如下:
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.Example 1:
Input: [-4,-1,0,3,10]
Output: [0,1,9,16,100]Example 2:
Input: [-7,-3,2,3,11]
Output: [4,9,9,49,121]Note:
1 <= A.length <= 10000
-10000 <= A[i] <= 10000
A
is sorted in non-decreasing order.
解题思路:在leetcode,还有比这更简单的题目吗?
闲聊:最近在出差,都没有时间刷题。今天刷个容易的题保持手感吧。
代码如下:
class Solution(object):
def sortedSquares(self, A):
"""
:type A: List[int]
:rtype: List[int]
"""
def f(x):
return x*x
return sorted(map(f,A))
【leetcode】977. Squares of a Sorted Array的更多相关文章
- 【LeetCode】977. Squares of a Sorted Array 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcod ...
- 【Leetcode_easy】977. Squares of a Sorted Array
problem 977. Squares of a Sorted Array solution: class Solution { public: vector<int> sortedSq ...
- 【leetcode】Find Minimum in Rotated Sorted Array I&&II
题目概述: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 ...
- 【LeetCode】Find Minimum in Rotated Sorted Array 解题报告
今天看到LeetCode OJ题目下方多了"Show Tags"功能.我觉着挺好,方便刚開始学习的人分类练习.同一时候也是解题时的思路提示. [题目] Suppose a sort ...
- 【leetcode】Find Minimum in Rotated Sorted Array II JAVA实现
一.题目描述 Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed ...
- 【leetcode】 26. Remove Duplicates from Sorted Array
@requires_authorization @author johnsondu @create_time 2015.7.22 18:58 @url [remove dublicates from ...
- 【LeetCode】26. Remove Duplicates from Sorted Array 解题报告(Python&C++&Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 日期 [LeetCode] https:// ...
- 【LeetCode】81. Search in Rotated Sorted Array II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/search-in ...
- 【LeetCode】80. Remove Duplicates from Sorted Array II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
随机推荐
- react 获取token
1.在action 中发送请求,j将获取得到的token 储存起来 到localhost //登陆发送请求 export const loginUser = (userData,history)= ...
- 双联通的tarjan算法
转自:https://www.zhihu.com/question/40746887/answer/88428236 连通分量有三种∶边双连通分量,点双连通分量,强连通分量,前两种属于无向图,后一种属 ...
- python函数参数*args **kwargs
毕业多年,把C++都就饭吃了....今天居然在纠结什么是形参什么是实参..... 定义函数里面写的参数就是形参,因为没有内存占用,实际调用时写的参数就是实参,因为有内存占用和传值 然后就是位置参数,可 ...
- 「NOI2017」游戏 解题报告
「NOI2017」游戏 \(d\)这么小,你考虑直接对\(d\)个东西暴力 枚举\(x\)为\(a\)或\(b\)(\(c\)就不用了,因为\(a,b\)已经包含\(c\))了,剩下的就是个\(2-s ...
- (转)使用OpenGL ES显示图像
编写:jdneo - 原文:http://developer.android.com/training/graphics/opengl/index.html 转:http://hukai.me/and ...
- hasvalue vs !=null
Which is preferred: Nullable<T>.HasValue or Nullable<T> != null? The compiler replaces n ...
- 69、schema的相关方法
public class SObjectSchema { public void testSchema(){ //获取SObject的token //1.先获取所有token,然后通过key获取需要的 ...
- 更改package.js后重新加载
node --save可有省略掉手动修改package.json的步骤 当你为你的模块安装一个依赖模块时,正常情况下你得先安装他们(在模块根目录下npm install module-name), ...
- python 自带http服务
python2: python -m SimpleHTTPServer python3: python3 -m http.server
- 13-python基础—python3中的map()
map() 会根据提供的函数对指定序列做映射. 第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表. 通俗解释: m ...