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 ...
随机推荐
- kafka快速开始
Step 1: Download the code Step 2: Start the server Step 3: Create a topic Step 4: Send some messages ...
- Spring Boot – 自定义PropertyEditor
前言 PropertyEditor最初是属于Java Bean规范定义的,有意思的是,Spring也大规模的使用了PropertyEditors,以便实现以各种形式展现对象的属性: 举个例子,常见的用 ...
- SpingBoot 属性加载
属性加载顺序 配置属性加载的顺序 开发者工具 `Devtools` 全局配置参数: 单元测试上的 `@TestPropertySource` 注解指定的参数: 单元测试上的 `@SpringBootT ...
- vmware vcsa-6.5 网络架构之虚拟机的标准交换机
一.配置虚拟机网络 1.概述(esxi 比workstation,vmware server,网络功能更强大) workstation和vmware server每块物理网卡可以给多个虚拟机使用,多个 ...
- Java并发(一)—— 使用多线程
Java的线程机制是抢占式的,所谓的抢占式指的是每一个线程都会被分配一个指定大小的时间片,一旦这个时间片用完,就会通过上下文切换到另一个线程上去. 并发是主要是为了提高单处理器的性能.创建一个线程会有 ...
- 【转载】C#生成图片的缩略图
图片处理是C#程序开发中时常会涉及到的一个业务,除了图像的上传.保存以及下载等功能外,根据上传的图片生成一个缩略图也是常见业务,在C#语言中,可以通过Image类提供的相关方法对图片进行操作,如指定宽 ...
- Python在Office 365 开发中的应用
我在昨天发布的文章 -- 简明 Python 教程:人生苦短,快用Python -- 中提到了Python已经在Office 365开发中全面受支持,有不同朋友留言或私信说想了解更加详细的说明,所以特 ...
- overall error
Overall error is same with total error in math.
- Promise是Monad吗?
译者按: 近年来,函数式语言的特性都被其它语言学过去了. 原文: Functional Computational Thinking — What is a monad? 译者: Fundebug 为 ...
- 不创建实体对象,利用newstonjson得到json格式字符串,键对应的值
1.Json字符串嵌套格式解析 string jsonText = "{\"beijing\":{\"zone\":\"海淀\", ...