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 ...
 
随机推荐
- HDU 1006 Tick and Tick 时钟指针问题
			
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
 - Code Complete-13/7/23
			
What is "construction"? Hava u ever used construction paper to make some things?What i ...
 - Unity教程之-UGUI美术字体的制作与使用
			
文章转载自:http://www.unity.5helpyou.com/3211.html 游戏制作中,经常需要使用各种花哨的文字或者数字,而字体库往往不能达到我们需要的效果,因此需要一种用图片替代文 ...
 - Nacos系列:基于Nacos的配置中心
			
前言 在看正文之前,我想请你回顾一下自己待过的公司都是怎么管理配置的,我想应该会有以下几种方式: 1.硬编码 没有什么配置不配置的,直接写在代码里面,比如使用常量类 优势:对开发友好,开发清楚地知道代 ...
 - 入侵感知系列之webshell检测思路
			
Webshell检测 背景: 在B/S架构为主流的当下,web安全成了攻防领域的主战场,其中上传webshell是所有web黑客入侵后一定会做的事,所以检测网站中是否有webshell程序是判断被 ...
 - [转]js 取得 Unix时间戳(Unix timestamp)
			
本文转自:https://blog.csdn.net/o0snow/article/details/6858829 js 取得 Unix时间戳 Unix时间戳(Unix timestamp),或称Un ...
 - 第一册:lesson thirty one。
			
原文:Where is Sally? A:Where is .. B? B:She is in the garden,A. A:What's she doing? B:She is sitting u ...
 - Spring Boot 设置静态资源访问
			
问题描述 当使用spring Boot来架设服务系统时,有时候也需要用到前端页面,当然就不可或缺地需要访问其他一些静态资源,比如图片.css.js等文件.那么如何设置Spring Boot网站可以访问 ...
 - Chrome插件开发,美化网页上的文件列表。chrome-extension,background
			
上一篇文章 通过“content-scripts”的方式向页面注入js和css来美化页面,但是有一个弊端:一旦配置好需要注入的页面,之后如果这个页面地址以后发生变化,或者要新加一些URL进来,那么得修 ...
 - FastReport.Net
			
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...