1、题目描述

2、代码

 void rotate(vector<int>& nums, int k) {

         if( k == )
return ;
if( k % nums.size() == && (k / nums.size()) % == )
reverse( nums.begin(), nums.end() ); k %= nums.size() ; vector<int> ans;
auto rb = nums.rbegin();
stack<int> s;
for( int i = k; i > ; i--,rb++)
{
s.push(*rb);
} while( !s.empty() )
{
int tmp = s.top();
ans.push_back(tmp);
s.pop(); }
auto b = nums.begin();
for( int j = ; j < nums.size() - k; j++,b++)
{
ans.push_back(*b);
}
copy(ans.begin(),ans.end(),nums.begin()); }

LeetCode题解之Rotate Array的更多相关文章

  1. 【LeetCode题解】数组Array

    1. 数组 直观地看,数组(Array)为一个二元组<index, value>的集合--对于每一个index,都有一个value与之对应.C语言中,以"连续的存储单元" ...

  2. 【LeetCode】189. Rotate Array 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 切片 递归 日期 题目地址:https://leet ...

  3. 【LeetCode】189 - Rotate Array

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  4. LeetCode OJ 189. Rotate Array

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  5. LeetCode算法题-Rotate Array(Java实现)

    这是悦乐书的第184次更新,第186篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第43题(顺位题号是189).给定一个数组,将数组向右旋转k步,其中k为非负数.例如: ...

  6. LeetCode题解:Rotate List

    Rotate List Given a list, rotate the list to the right by k places, where k is non-negative. For exa ...

  7. (LeetCode 189)Rotate Array

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...

  8. LeetCode OJ:Rotate Array(倒置数组)

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  9. LeetCode 题解之Rotate List

    1.题目描述 2.题目分析 首先数出链表中的元素个数count,然后对k = k % count 求余数.接着将链表形成一个环,从最后一个元素开始,运动 count - k  步,此时节点的下一个节点 ...

随机推荐

  1. 【Gitbook】实用配置及插件介绍

    前言 实际效果可以查看这里 github地址 配置 title 设置书本的标题 "title" : "Gitbook Use" author 作者的相关信息 & ...

  2. Linux 线程占用CPU过高定位分析

    今天朋友问我一个Linux程序CPU占用涨停了,该如何分析, CPU占用过高,模拟CPU占用过高的情况 先上一段代码: #include <iostream> #include <t ...

  3. windows 64位 下 安装 tomcat

    tomcat 版本 windows 64位 .zip apache-tomcat-7.0.42.zip 注意: 1. 安装目录不得有 空格 或 中文字符 2. 然后,在系统环境变量下,新建一个变量: ...

  4. Office Visio 201*安装详细步骤并激活

    不多说直接上干货! 初步了解:  Visio的百度百科:http://baike.baidu.com/link?url=tNv_gqhhVKcurpP8kvh4ylkknc5JQLIm6bGmQVxi ...

  5. 问题记录 | VScode中使用IntelliJ的快捷键

    问题记录 | VScode中使用IntelliJ的快捷键 主要想用ctrl+alt+l格式化Python代码 安装VScode的插件:IntelliJ IDEA Keybindings 安装方法: I ...

  6. 数据序列化导读(1)[JSON]

    所谓数据序列化(Data Serialization), 就是将某个对象的状态信息转换为可以存储或传输的形式的过程. 那么,为什么要进行序列化? 首先,为了方便数据存储: 其次,为了方便数据传递. 在 ...

  7. linux svn 自启动

    .svn服务自启动脚本 把脚本放在/etc/init.d/下 vi /etc/rc.d/init.d/svn svn脚本内容: #!/bin/bash # chkconfig: - # descrip ...

  8. java 序列化与解序列化

    小例 import java.io.*; public class Box implements Serializable{ private int width; private int height ...

  9. 表单提交.serialize()方法

    html中<form id="myForm" action="..." method='POST'> <div><input ty ...

  10. jQuery+Ajax+PHP 制作简单的异步数据传输(测试用户名是否可用)

    实现基本异步数据传输,略去与数据库交换,先直接在PHP端判断:用户名为 user1 即为不可用, 测试时外加了 普遍的 “Loading..." 功能,此功能可直接在PHP中循环延时 for ...