当前位置:网站首页>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 k
is 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
边栏推荐
- Usage of += in C#
- 爱可可AI前沿推介(7.31)
- leetcode:485.最大连续 1 的个数
- IDEA连接MySQL数据库并使用数据
- LeetCode旋转数组
- Productivity Tools and Plugins
- [Niu Ke brush questions - SQL big factory interview questions] NO3. E-commerce scene (some east mall)
- uniapp微信小程序引用标准版交易组件
- The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars
- hyperf的启动源码分析(二)——请求如何到达控制器
猜你喜欢
随机推荐
C# control StatusStrip use
ICML2022 | 面向自监督图表示学习的全粒度自语义传播
leetcode:485.最大连续 1 的个数
STM32——软件SPI控制AD7705[通俗易懂]
EasyMock日记1[通俗易懂]
hyperf的启动源码分析(二)——请求如何到达控制器
Linux bash: redis-server: 未找到命令
Edge Cloud Explained in Simple Depth | 4. Lifecycle Management
The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars
Samba 远程命令执行漏洞(CVE-2017-7494)
ADS与C#通信
C#控件StatusStrip使用
技能大赛训练题:域用户和组织单元的创建
STM32的CAN过滤器
C语言基础练(九九乘法表)与打印不同星号图案
Text similarity calculation (Chinese and English) detailed explanation of actual combat
技能大赛训练题:MS15_034漏洞验证与安全加固
The importance of strategic offensive capability is much higher than strategic defensive capability
爱可可AI前沿推介(7.31)
golang-gin-pprof-使用以及安全问题