当前位置:网站首页>LeetCode rotate array
LeetCode rotate array
2022-07-31 13:47:00 【Super love to learn Yun】
Given an array, rotate the elements of the array to the right by k positions, where kis a non-negative number.
Input: nums = [1,2,3,4,5,6,7], k = 3
Output: [5,6,7,1,2,3,4]
Explanation:
Rotate 1 step to the right: [7,1,2,3,4,5,6]
Rotate 2 steps to the right: [6,7,1,2,3,4,5]
Rotate 3 steps to the right: [5,6,7,1,2,3,4]
Input: nums = [-1,-100,3,99], k = 2
Output: [3,99,-1,-100]
Explanation:
Rotate right by 1Step: [99,-1,-100,3]
Rotate right 2 steps: [3,99,-1,-100]
How to solve the problem:
Create a new array, number[(i+k)%numsSize]=nums[i]
Assign to a new array
Code display:
void rotate(int* nums, int numsSize, int k){int number[numsSize];for(int i=0;i边栏推荐
- An article makes it clear!What is the difference and connection between database and data warehouse?
- 推荐系统-召回阶段-2013:DSSM(双塔模型)【Embedding(语义向量)召回】【微软】
- ECCV2022: Recursion on Transformer without adding parameters and less computation!
- Grab the tail of gold, silver and silver, unlock the programmer interview "Artifact of Brushing Questions"
- Shell脚本经典案例:探测批量主机是否存活
- 基于神经网络的多柔性梁耦合结构振动控制
- All-round visual monitoring of the Istio microservice governance grid (microservice architecture display, resource monitoring, traffic monitoring, link monitoring)
- 新款现代帕里斯帝预售开启,安全、舒适一个不落
- uniapp微信小程序引用标准版交易组件
- What should I do if selenium is reversed?
猜你喜欢
随机推荐
[Niu Ke brush questions - SQL big factory interview questions] NO3. E-commerce scene (some east mall)
Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)
Edge Cloud Explained in Simple Depth | 4. Lifecycle Management
All-round visual monitoring of the Istio microservice governance grid (microservice architecture display, resource monitoring, traffic monitoring, link monitoring)
滑窗法切分数据
Spark学习:为Spark Sql添加自定义优化规则
Use of C# Assembly
Even if the image is missing in a large area, it can also be repaired realistically. The new model CM-GAN takes into account the global structure and texture details
Six Stones Programming: No matter which function you think is useless, people who can use it will not be able to leave, so at least 99%
Network layer key protocol - IP protocol
【redis】发布和订阅消息
VU 非父子组件通信
C# using ComboBox control
Batch大小不一定是2的n次幂!ML资深学者最新结论
3.爬虫之Scrapy框架1安装与使用
Usage of += in C#
MySQL玩到这种程度,难怪大厂抢着要!
Shell项目实战1.系统性能分析
基于改进YOLOv5的轻量化航空目标检测方法
uniapp微信小程序引用标准版交易组件









