LeetCode题解之Squares of a Sorted Array
1、题目描述

2、问题分析
使用过两个计数器。
3、代码
class Solution {
public:
vector<int> sortedSquares(vector<int>& A) {
int left = , right = A.size() - ;
vector<int> res;
while (left <= right) {
if (abs(A[left]) >= abs(A[right])) {
res.push_back(A[left] * A[left]);
left++;
} else {
res.push_back(A[right] * A[right]);
right--;
}
}
reverse(res.begin(), res.end());
return res;
}
};
LeetCode题解之Squares of a Sorted Array的更多相关文章
- LeetCode题解33.Search in Rotated Sorted Array
33. Search in Rotated Sorted Array Suppose an array sorted in ascending order is rotated at some piv ...
- leetcode 题解:Search in Rotated Sorted Array II (旋转已排序数组查找2)
题目: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would t ...
- leetcode题解:Search 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 ...
- leetcode 题解:Remove Duplicates from Sorted Array II(已排序数组去三次及以上重复元素)
题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...
- leetcode 题解:Remove Duplicates from Sorted Array(已排序数组去重)
题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- 【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 ...
- [Leetcode][Python]33: Search in Rotated Sorted Array
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 33: Search in Rotated Sorted Arrayhttps ...
- [Leetcode][Python]26: Remove Duplicates from Sorted Array
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 26: Remove Duplicates from Sorted Array ...
随机推荐
- 小程序开发--移动端分辨率与rpx
首先说一个很有意思的问题:一块720p的屏幕和1080p的屏幕那个大? 这个问题很有代表性,如果手机竖着放,720p=720px*1280px,而1080p=1080px*1920px;那么在宽度上, ...
- Java I/O : Bit Operation 位运算
Writer :BYSocket(泥沙砖瓦浆木匠) 微 博:BYSocket 豆 瓣:BYSocket FaceBook:BYSocket Twitter ...
- 【EF6学习笔记】(十二)EF高级应用场景
本篇原文链接:Advanced Entity Framework Scenarios 本篇主要讲一些使用Code First建立ASP.NET WEB应用的时候除了基础的方式以外的一些扩展方式方法: ...
- JavaScript和Ajax部分(3)
21. 原生(native)Ajax使用实例 //创建XMLHttpRequest对象的方法 function createXmlHttpRequest(){ if(window.ActiveXObj ...
- 【Flask-RESTPlus系列】Part2:响应编组
0x00 内容概览 响应编组 基本使用 重命名属性 默认值 自定义字段及多值情况 Url及其他具体字段 复杂结构 列表字段 嵌套字段 api.model()工厂 clone实现复制 api.inher ...
- Perl和操作系统交互(二):fork
fork + exec fork是低层次的系统调用,通过复制父进程来创建子进程. fork的行为 fork用来拷贝当前进程,生成一个基本完全一样的子进程. my $pid=fork(); 如果fork ...
- 搞懂Python的类和对象名称空间
代码块的分类 python中分几种代码块类型,它们都有自己的作用域,或者说名称空间: 文件或模块整体是一个代码块,名称空间为全局范围 函数代码块,名称空间为函数自身范围,是本地作用域,在全局范围的内层 ...
- 使用meterpreter让没有安装python解释器的肉鸡设备执行任意python程序
目标设备不需安装python解释器就能让其执行python程序 # 需要在与目标meterpreter的session中加载python模块 meterpreter > load python ...
- [转]MySQL修改时区的方法小结
本文转自:https://www.cnblogs.com/mracale/p/6064447.html 这篇文章主要介绍了MySQL修改时区的方法,总结分析了三种常见的MySQL时区修改技巧,包括命令 ...
- Ioc原理理解
IoC理论的背景 我们都知道,在采用面向对象方法设计的软件系统中,它的底层实现都是由N个对象组成的,所有的对象通过彼此的合作,最终实现系统的业务逻辑. 如果我们打开机械式手表的后盖,就会看到与上面类似 ...