【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. 1 <= A.length <= 10000
  2. -10000 <= A[i] <= 10000
  3. 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))

原文地址:https://www.cnblogs.com/seyjs/p/10295036.html

时间: 2024-08-30 03:47:20

【leetcode】977. Squares of a Sorted Array的相关文章

【Leetcode_easy】977. Squares of a Sorted Array

problem 977. Squares of a Sorted Array solution: class Solution { public: vector<int> sortedSquares(vector<int>& A) { for(auto &a:A) a *=a; sort(A.begin(), A.end()); return A; } }; 参考1. Leetcode_easy_977. Squares of a Sorted Array; 完 原

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

今天看到LeetCode OJ题目下方多了"Show Tags"功能.我觉着挺好,方便刚開始学习的人分类练习.同一时候也是解题时的思路提示. [题目] Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no

【leetcode】Find Minimum in Rotated Sorted Array JAVA实现

一.题目描述 Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no duplicate exists in the array. 二.分析 这题难度有,因为他默认的是数组中所有的元素是不同的.只有分为两种情况: 1.

【LeetCode】Find Minimum in Rotated Sorted Array 在旋转数组中找最小数

Add Date 2014-10-15 Find Minimum in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no duplicate exists in the

【leetcode】Find Minimum in Rotated Sorted Array II JAVA实现

一.题目描述 Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 m

【leetcode】26. Remove Duplicates from Sorted Array

题目描述: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. 解题分析: 扫描一遍链表,用一个变量标记已找到的不重复的元

【LeetCode】26. Remove Duplicates from Sorted Array 解题小结

题目: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. For example,Given input array n

【LeetCode】Find Minimum in Rotated Sorted Array 找到旋转后有序数组中的最小值

本文原作者:大便一箩筐 文章原地址:http://www.cnblogs.com/dbylk/p/4032570.html 原题: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no duplicate exist

【LeetCode】83 - Remove Duplicates from Sorted Array

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. For example,Given input array nums