当前位置:网站首页>189. rotation array
189. rotation array
2022-06-11 21:44:00 【Code loving students】
Title Description :
Give you an array , Rotate the elements in the array to the right k A place , among k It is a non negative number .
Topic analysis :
1. Move array
We store the last element in the array , Then move the entire array , Finally, put the stored element in the first position , repeat k Time .
Let's set the array here to be num[7]={1,2,3,4,5,7,}
k=3
The code is as follows :
2. Open up additional arrays
We can put the element in the position after moving in advance , Finally assigned to the original array
The code is as follows :
3. Array rotation
operation result 1 2 3 4 5 6 7 1 2 3 4 5 6 7 Flip [0,numsSize-1-k] 4 3 2 1 5 6 7 Flip [numsSize-k,numsSize-1] 4 3 2 1 7 6 5 Flip the entire array 5 6 7 1 2 3 4 The code implementation is as follows :
边栏推荐
- Leetcode-104- maximum depth of binary tree
- Redis data type (string)
- Leetcode-76- minimum covering substring
- LabVIEW Arduino electronic weighing system (project Part-1)
- LabVIEW Arduino电子称重系统(项目篇—1)
- How to import workflows provided on SAP API hub to sap BTP
- C语言实现八种排序(3)
- Leetcode-98- validate binary search tree
- C语言实现八种排序(2)
- AC自动机
猜你喜欢

206.反转链表

LeetCode-98-验证二叉搜索树

联调这夜,我把同事打了...

C语言实现迷宫问题

Leetcode-76- minimum covering substring

LaTex实战笔记 3-宏包与控制命令

The same efficiency tool for leading enterprises to promote smart finance. Let's have a quick look?

Apache local multi port configuration

2021 Niuke multi school 5 double strings

Database daily question --- day 9: salesperson
随机推荐
Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
Cdr2022 serial number coreldraw2022 green key
动态内存管理(1)
[Part 16] copyonwritearraylist source code analysis and application details [key]
Software test plan
JVM|虚拟机栈(局部变量表;操作数栈;动态链接;方法的绑定机制;方法的调用;方法返回地址)
AC自动机
C语言实现八种排序(2)
Leetcode - 第2天
Redis Foundation
Add anti debugging function to game or code (application level)
Carry and walk with you. Have you ever seen a "palm sized" weather station?
Jenkins+allure integrated report construction
Redis basic data type (list)
类和对象(2)
JVM|前言介绍
JVM | introduction
Database daily question --- day 9: salesperson
LeetCode-155-最小栈
Experiment 10 Bezier curve generation - experiment improvement - control point generation of B-spline curve


