当前位置:网站首页>LeetCode每日两题02:轮转数组 (均1200道)
LeetCode每日两题02:轮转数组 (均1200道)
2022-08-09 01:13:00 【那人独钓寒江雪.】
解题思路:使用额外的数组 ,通过 arr[(i+k)%n]=nums[i]等式进行位置转换
并且使用arraycopy函数 将额外数组复制到本数组中。
class Solution {
public void rotate(int[] nums, int k) {
int n=nums.length;//[1,2,3,4,5,6,7] k=3
int[] arr=new int[n];
for (int i=0;i<nums.length;i++){
arr[(i+k)%n]=nums[i];
}
System.arraycopy(arr,0,nums,0,n);
}
}
边栏推荐
猜你喜欢
《Go语言学习:基本变量与类型》
clickhouse 思维导图
软件测试的调用接口怎么调用,逻辑是什么?
『Another Redis DeskTop Manager』用了这款Redis可视化工具,分析效率提升12倍
全文翻译:EDPB数据保护影响评估(DPIA:Data Protection Impact Assessment)指南
Bugs encountered in remote control projects
面试秘籍 | 软件测试必备的mysql数据库技术
A double non-programmer interviewed Ant, Meituan, Ctrip and other big companies with offers to share the interview process
Use Ehcache distributed cache to easily create commercial-grade high-concurrency, high-performance API interfaces!
Using MySQL on Windows: Automatic Scheduled Backups
随机推荐
字符串压缩
面试秘籍 | 软件测试必备的mysql数据库技术
【元胞自动机】基于元胞自动机模拟社会力因素下的灾害人员疏散应急仿真附matlab代码
「复盘」面试 BAMT 回来整理 398 道高频面试题,助你拿高薪 offer
Unified identity management platform IAM single sign-on process and third-party interface design scheme
Pinctrl 子系统简介
一名双非程序媛面试蚂蚁、美团、携程等大厂拿 offer 分享面试过程
如何仿造一个websocket请求?
torch.utils.data.DataLoader
Wireshark packet capture tool
轻量级CNN网络高效设计准则-ShuffleNet v2学习记录
【物理应用】基于El-centro地震波作用下隔震与非隔震支座下的顶层位移、速度、加速度的对比情况附matlab代码
【学习-目标检测】目标检测之——YOLO v3
Use Ehcache distributed cache to easily create commercial-grade high-concurrency, high-performance API interfaces!
利用Ehcache分布式缓存,轻松打造商业级高并发、高性能API接口!
Transformer前言:self-attention与Multi-Headed Attention的详细理解
5-4 Seaborn 线性回归绘图
LVGL简介(基于v8.1-8.2)
4-6 Matplotlib库 饼图
"Replay" interview BAMT came back to sort out 398 high-frequency interview questions to help you get a high salary offer