当前位置:网站首页>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边栏推荐
- 报错:npm ERR code EPERM
- Unity study notes Description of AVPro video jump function (Seeking)
- C#Assembly的使用
- [Niu Ke brush questions - SQL big factory interview questions] NO3. E-commerce scene (some east mall)
- 「面经分享」西北大学 | 字节 生活服务 | 一面二面三面 HR 面
- MySQL玩到这种程度,难怪大厂抢着要!
- The latest complete code: Incremental training using the word2vec pre-training model (two loading methods corresponding to two saving methods) applicable to various versions of gensim
- Sliding window method to segment data
- uniapp微信小程序引用标准版交易组件
- 新款现代帕里斯帝预售开启,安全、舒适一个不落
猜你喜欢

报错:npm ERR code EPERM

PHP Serialization: eval

LeetCode·304竞赛·6132·使数组中所有元素都等于零·模拟·哈希

C#使用ComboBox控件

C#控件ListView用法

C#控件CheckBox的使用

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

Error IDEA Terminated with exit code 1

ECCV 2022 | 机器人的交互感知与物体操作

IDEA找不到Database解决方法
随机推荐
Use of C# Assembly
IDEA连接MySQL数据库并使用数据
为什么 wireguard-go 高尚而 boringtun 孬种
关于MySQL主从复制的数据同步延迟问题
endnote引用
golang-gin-pprof-使用以及安全问题
PHP Serialization: eval
numpy矩阵和向量的保存与加载,以及使用保存的向量进行相似度计算
Spark Learning: Add Custom Optimization Rules for Spark Sql
使用CompletableFuture进行异步处理业务
ADS与C#通信
技能大赛dhcp服务训练题
C#中+=的用法
Productivity Tools and Plugins
C# Get network card information NetworkInterface IPInterfaceProperties
C#控件 ToolStripProgressBar 用法
基于高阶微分器的无模型滑模控制器及其在自动电压调节器中的应用
Golang - gin - pprof - use and safety
使用NVM进行node版本切换管理
Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)