LeetCode977.Squares of a Sorted Array
题目
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.
答案
func sortedSquares(A []int) []int {
size := len(A)
res := make([]int, size)
for l, r, i := 0, size-1, size-1; l <= r; i-- {
if A[l]+A[r] < 0 {
res[i] = A[l] * A[l]
l++
} else {
res[i] = A[r] * A[r]
r--
}
}
return res
}
参考链接
977. Squares of a Sorted Array
LeetCode977.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> sortedSq ...
- [Swift]LeetCode977. 有序数组的平方 | Squares of a Sorted Array
Given an array of integers A sorted in non-decreasing order, return an array of the squares of each ...
- #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- ...
- 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 ...
- Squares of a Sorted Array LT977
Given an array of integers A sorted in non-decreasing order, return an array of the squares of each ...
- 977. Squares of a Sorted Array
题目描述: Given an array of integers A sorted in non-decreasing order, return an array of the squares of ...
- Squares of a Sorted Array
Given an array of integers A sorted in non-decreasing order, return an array of the squares of each ...
- 【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 ...
- 【LeetCode】977. Squares of a Sorted Array 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcod ...
随机推荐
- XA 事务
4.11.3 什么是XA 事务? <数据库程序员面试笔试宝典>第4章数据库基础,本章主要介绍数据库基础部分的面试题,比较适合应届毕业生,也适合由其他岗位转数据库岗位的人员.本节为大家介绍什 ...
- 集成omnibus-ctl 开发一个专业的软件包管理工具
前边有转发过来自chef 团队的一篇omnibus-ctl 介绍文章,以下尝试进行项目试用 就是简单的集成,没有多少复杂的操作 环境准备 ruby ruby 使用2.6.3 使用 rbenv 安装,可 ...
- CF1237C2 【Balanced Removals (Harder)】
这么妙的题怎么没人发题解啊 首先这是三维的,我们可以对其进行降维打击 先考虑一维怎么做? 我们可以对其该维坐标进行排序,按照顺序输出,可能会多余一个 那拓展到二维呢? 我们可以把它转化成一维,分成很多 ...
- uni app 零基础小白到项目实战-1
uni-app是一个使用vue.js开发跨平台应用的前端框架. 开发者通过编写vue.js代码,uni-app将其编译到Ios,android,微信小程序等多个平台,保证其正确并达到优秀体验. Uni ...
- Web前端开发(高级)下册-目录
多媒体与绘图 多媒体音频格式视频格式 HTML5多媒体支持 <audio>和<video> htmlaudioElement和htmlVideoElement <audi ...
- 前端微信小程序资讯类仿今日头条微信小程序
需求描述及交互分析设计思路和相关知识点新闻频道滑动效果设计首页新闻内容设计首页新闻详情页设计我的界面列表式导航设计系统设置二级界面设计 设计思路(1)设计底部标签导航,准备好底部标签导航的图标和建立相 ...
- mysql distinct()函数 去重
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | t ...
- csp退役前的做题计划1(真)
csp退役前的做题计划1(真) 因为我太菜了,所以在第一次月考就会退役,还是记录一下每天做了什么题目吧. 任务计划 [ ] Z算法(Z Algorithm) 9.28 [x] ARC061C たくさん ...
- python3中Requests将verify设置为False后,取消警告的方式
import requests resp = requests.get('https://www.***.com', verify=False) 调用成功但是会有如下警告信息: InsecureReq ...
- 2019暑假Java学习笔记(一)
目录 基础语法(上) HelloWorld 变量 常量 数据类型 整数 浮点数 char类型 boolean类型 String 计算字符串长度 字符串比较 字符串连接 charAt()方法 字符串常用 ...