当前位置:网站首页>[leetcode] 189 rotation array
[leetcode] 189 rotation array
2022-07-02 15:36:00 【Crisp ~】
Give you an array , Rotate the elements in the array to the right k A place , among k It is a non negative number .
Example 1:
Input : nums = [1,2,3,4,5,6,7], k = 3
Output : [5,6,7,1,2,3,4]
explain :
Rotate right 1 Step : [7,1,2,3,4,5,6]
Rotate right 2 Step : [6,7,1,2,3,4,5]
Rotate right 3 Step : [5,6,7,1,2,3,4]
Example 2:
Input : nums = [-1,-100,3,99], k = 2
Output : [3,99,-1,-100]
explain :
Rotate right 1 Step : [99,-1,-100,3]
Rotate right 2 Step : [3,99,-1,-100]
Tips :
- 1 <= nums.length <= 105
- -231 <= nums[i] <= 231 - 1
- 0 <= k <= 105
Advanced :
Come up with as many solutions as you can , There are at least Three Different methods can solve this problem .
You can use a spatial complexity of O(1) Of In situ Does the algorithm solve this problem ?
# utilize python Sequence characteristics
class Solution(object):
def rotate(self, nums, k):
n = len(nums)
k = k%n
nums[:] = nums[n-k:]+nums[:n-k]
return nums
边栏推荐
- 让您的HMI更具优势,FET-G2LD-C核心板是个好选择
- Pytorch 保存tensor到.mat文件
- folium,确诊和密接轨迹上图
- 03. Preliminary use of golang
- 04_ 栈
- Markdown tutorial
- 04.进入云原生后的企业级应用构建的一些思考
- Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
- 19_ Redis_ Manually configure the host after downtime
- 04. Some thoughts on enterprise application construction after entering cloud native
猜你喜欢

21_Redis_浅析Redis缓存穿透和雪崩

Leetcode skimming -- verifying the preorder serialization of binary tree # 331 # medium

Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568

NBA player analysis

SQL stored procedure

百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香

17_Redis_Redis发布订阅

03.golang初步使用

03_線性錶_鏈錶

19_Redis_宕机后手动配置主机
随机推荐
Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
08_ strand
彻底弄懂浏览器强缓存和协商缓存
Basic knowledge of cryptography
【LeetCode】1020-飞地的数量
YOLOV5 代码复现以及搭载服务器运行
Evaluation of embedded rz/g2l processor core board and development board of Feiling
【LeetCode】876-链表的中间结点
03. Preliminary use of golang
Libcurl Lesson 13 static library introduces OpenSSL compilation dependency
03.golang初步使用
Set set you don't know
LeetCode刷题——递增的三元子序列#334#Medium
Common English abbreviations for data analysis (I)
Wechat Alipay account system and payment interface business process
Solve the problem of frequent interruption of mobaxterm remote connection
There are 7 seats with great variety, Wuling Jiachen has outstanding product power, large humanized space, and the key price is really fragrant
损失函数与正负样本分配:YOLO系列
怎样从微信返回的json字符串中截取某个key的值?
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!