当前位置:网站首页>189. 轮转数组
189. 轮转数组
2022-06-11 21:36:00 【爱学代码的学生】
题目描述:
给你一个数组,将数组中的元素向右轮转 k个位置,其中 k是非负数。
题目分析:
1. 移动数组
我们存储数组中的最后一个元素,然后移动整个数组,最后把存储的元素放在第一个位置,重复k次。
我们这里设数组是num[7]={1,2,3,4,5,7,}
k=3
代码如下:
2. 开辟额外的数组
我们可以提前将元素放在移动后的位置,最后赋值给原数组
代码如下:
3. 数组旋转
操作 结果 1 2 3 4 5 6 7 1 2 3 4 5 6 7 翻转[0,numsSize-1-k] 4 3 2 1 5 6 7 翻转[numsSize-k,numsSize-1] 4 3 2 1 7 6 5 翻转整个数组 5 6 7 1 2 3 4 代码实现如下:
边栏推荐
- LabVIEW控制Arduino实现超声波测距(进阶篇—5)
- 行而不辍,未来可期|云扩科技入选上海市专精特新企业
- 实现 TabLayout 下标与文字等长,选中字体大小改变
- Educational Codeforces Round 114 (Rated for Div. 2) D
- Codeforces Round #742 (Div. 2) F. One-Four Overload
- RPA+低代码助推品牌电商启新创变、重启增长
- Leetcode-322- change exchange
- Jenkins+allure integrated report construction
- EndnoteX9簡介及基本教程使用說明
- Software test plan
猜你喜欢

Answer fans' questions | count the number and frequency of letters in the text

【C語言進階】整型在內存中的存儲

Leetcode-129- sum of numbers from root node to leaf node

Apache local multi port configuration

Codeforces Round #744 (Div. 3) 解题报告

Introduction à endnotex9 et instructions pour les tutoriels de base

Leetcode-98- validate binary search tree

Flutter series: detailed explanation of container layout commonly used in flutter

RPA+低代码为何是加速财务数字化转型之利器?

Building a custom CNN model: identifying covid-19
随机推荐
JVM|前言介绍
RPA+低代码为何是加速财务数字化转型之利器?
LeetCode-98-验证二叉搜索树
servlet获取表单数据
Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
JUnit tests multithreaded code, and the sub thread does not run
BZOJ3189 : [Coci2011] Slika
Redis transaction
Only 38 years old! Zhou Chuan, a researcher of the Chinese Academy of Sciences, died unfortunately. Rao Yi sent a document to mourn: he guided me when he was still my student
Chain storage structure of linear table
LabVIEW controls Arduino to realize infrared ranging (advanced chapter-6)
Experiment 10 Bezier curve generation - experiment improvement - interactive generation of B-spline curve
LeetCode-129-求根节点到叶节点数字之和
领先企业推进智慧财务的同款效率工具,赶快了解一下?
实现 TabLayout 下标与文字等长,选中字体大小改变
BZOJ3189 : [Coci2011] Slika
[Part 13] source code analysis and application details of completabilefuture class [key]
Codeworks round 744 (Div. 3) problem solving Report
How to import workflows provided on SAP API hub to sap BTP
LabVIEW Arduino electronic weighing system (project Part-1)


