当前位置:网站首页>2022-7-6 Leetcode 977. Square of ordered array
2022-7-6 Leetcode 977. Square of ordered array
2022-07-07 13:39:00 【weixin_ fifty-one million one hundred and eighty-seven thousand】
Why should the cycle condition be set i <= j?
Because in the end i and j At the same time, point to the smallest number .
class Solution {
public:
vector<int> sortedSquares(vector<int>& nums) {
vector<int> result(nums.size(), 0);
int k = nums.size()-1;
int i = 0, j = nums.size()-1;
while (i <= j){
if (nums[i]*nums[i] < nums[j]*nums[j]){
result[k--] = nums[j]*nums[j];
j--;
}else {
result[k--] = nums[i]*nums[i];
i++;
}
}
return result;
}
};
边栏推荐
- [QNX Hypervisor 2.2用户手册]6.3.4 虚拟寄存器(guest_shm.h)
- Vscode编辑器ESP32头文件波浪线不跳转彻底解决
- .net core 关于redis的pipeline以及事务
- Clion mingw64 Chinese garbled code
- Pcap learning notes II: pcap4j source code Notes
- Leecode3. Longest substring without repeated characters
- 为租客提供帮助
- mysql 局域网内访问不到的问题
- Storage principle inside mongodb
- Use of polarscatter function in MATLAB
猜你喜欢
交付效率提升52倍,运营效率提升10倍,看《金融云原生技术实践案例汇编》(附下载)
【黑马早报】华为辟谣“军师”陈春花;恒驰5预售价17.9万元;周杰伦新专辑MV 3小时播放量破亿;法华寺回应万元月薪招人...
供应链供需预估-[时间序列]
Esp32 construction engineering add components
数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】
数字ic设计——SPI
Build a secure and trusted computing platform based on Kunpeng's native security
[Presto profile series] timeline use
室內ROS機器人導航調試記錄(膨脹半徑的選取經驗)
Navicat运行sql文件导入数据不全或导入失败
随机推荐
Deep understanding of array related problems in C language
postgresql array类型,每一项拼接
Solve the cache breakdown problem
【日常训练--腾讯精选50】231. 2 的幂
JS缓动动画原理教学(超细节)
Ikvm of toolbox Net project new progress
简单好用的代码规范
LED light of single chip microcomputer learning notes
LeetCode_ Binary search_ Medium_ 153. Find the minimum value in the rotation sort array
10 pictures open the door of CPU cache consistency
What parameters need to be reconfigured to replace the new radar of ROS robot
566. 重塑矩阵
【等保】云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
Pcap learning notes II: pcap4j source code Notes
2022-7-6 Leetcode27.移除元素——太久没有做题了,为双指针如此狼狈的一天
作战图鉴:12大场景详述容器安全建设要求
2022-7-7 Leetcode 34.在排序数组中查找元素的第一个和最后一个位置
记一次 .NET 某新能源系统 线程疯涨 分析
Vscode编辑器ESP32头文件波浪线不跳转彻底解决
一文读懂数仓中的pg_stat