当前位置:网站首页>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;
}
};
边栏推荐
- 如何让join跑得更快?
- Flink | multi stream conversion
- Split screen bug notes
- Getting started with MySQL
- PAcP learning note 3: pcap method description
- Mongodb meets spark (for integration)
- ESP32构解工程添加组件
- Build a secure and trusted computing platform based on Kunpeng's native security
- LeetCode简单题分享(20)
- Indoor ROS robot navigation commissioning record (experience in selecting expansion radius)
猜你喜欢
Cinnamon taskbar speed
Talk about pseudo sharing
MongoDB内部的存储原理
[Presto profile series] timeline use
Detr introduction
Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)
1、深拷贝 2、call apply bind 3、for of for in 区别
[learning notes] agc010
My "troublesome" subordinates after 00: not bad for money, against leaders, and resist overtime
数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】
随机推荐
Digital IC Design SPI
《厌女:日本的女性嫌恶》摘录
JS function returns multiple values
Cinnamon taskbar speed
Error lnk2019: unresolved external symbol
566. 重塑矩阵
提升树莓派性能的方法
How to make the new window opened by electorn on the window taskbar
存储过程的介绍与基本使用
Data refresh of recyclerview
My "troublesome" subordinates after 00: not bad for money, against leaders, and resist overtime
最佳实践 | 用腾讯云AI意愿核身为电话合规保驾护航
Clion mingw64 Chinese garbled code
User management summary of mongodb
供应链供需预估-[时间序列]
Read PG in data warehouse in one article_ stat
Indoor ROS robot navigation commissioning record (experience in selecting expansion radius)
[learning notes] segment tree selection
Simple and easy-to-use code specification
高端了8年,雅迪如今怎么样?