当前位置:网站首页>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;
}
};
边栏推荐
- Deep understanding of array related problems in C language
- 648. 单词替换 : 字典树的经典运用
- Build a secure and trusted computing platform based on Kunpeng's native security
- Digital IC Design SPI
- [1] Basic knowledge of ros2 - summary version of operation commands
- LeetCode_二分搜索_中等_153.寻找旋转排序数组中的最小值
- JS slow motion animation principle teaching (super detail)
- 实现IP地址归属地显示功能、号码归属地查询
- .net core 关于redis的pipeline以及事务
- clion mingw64中文乱码
猜你喜欢
Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
Sliding rail stepping motor commissioning (national ocean vehicle competition) (STM32 master control)
2022-7-7 Leetcode 844.比较含退格的字符串
如何让join跑得更快?
室内ROS机器人导航调试记录(膨胀半径的选取经验)
Use of polarscatter function in MATLAB
Ogre introduction
Introduction and basic use of stored procedures
ESP32 ① 编译环境
Show the mathematical formula in El table
随机推荐
How to make join run faster?
存储过程的介绍与基本使用
PAcP learning note 3: pcap method description
2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis
Redis只能做缓存?太out了!
Flink | 多流转换
OSI 七层模型
Drawerlayout suppress sideslip display
clion mingw64中文乱码
Thread pool reject policy best practices
云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
LeetCode简单题分享(20)
How did Guotai Junan Securities open an account? Is it safe to open an account?
MongoDB的用户管理总结
Learning breakout 2 - about effective learning methods
Server to server (S2S) event (adjust)
Build a secure and trusted computing platform based on Kunpeng's native security
Custom thread pool rejection policy
Data refresh of recyclerview
[QNX hypervisor 2.2 user manual]6.3.4 virtual register (guest_shm.h)