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. C# 通过IEnumberable接口和IEnumerator接口实现泛型和非泛型自定义集合类型foreach功能

    IEnumerator和IEnumerable的作用 其实IEnumerator和IEnumerable的作用很简单,就是让除数组和集合之外的类型也能支持foreach循环,至于foreach循环,如 ...

  2. 手风琴图片和钢琴导航栏JQ滑动特效

    手风琴JQ滑动特效 1.效果预览: 2.相关代码: <!DOCTYPE html> <html lang="en"> <head> <me ...

  3. Android六大基本布局

    一.基本理论Android六大基本布局分别是:线性布局LinearLayout.表格布局TableLayout.相对布局RelativeLayout.层布局FrameLayout.绝对布局Absolu ...

  4. Android4.0 Launcher 源码分析2——Launcher内容加载绑定详细过程

    Launcher在应用启动的时候,需要加载AppWidget,shortcut等内容项,通过调用LauncherModel.startLoader(),开始加载的工作.launcherModel中加载 ...

  5. LDAP落地实战(一):OpenLDAP部署及管理维护

    公司内部会有许多第三方系统或服务,例如Svn,Git,VPN,Jira,Jenkins等等,每个系统都需要维护一份账号密码以支持用户认证,当然公司也会有许多的主机或服务器,需要开放登录权限给用户登录使 ...

  6. pandas数据分析

    本篇主要介绍如何用pandas来分析一份刚拿到的数据集,即做数据挖掘或清洗的工作. 这里以贷款申请预测的数据来作为例子 一.查看基本信息 拿到数据首先看看大致结构,查看行列数,dataframe数据结 ...

  7. Linux 文件内容查看工具介绍-cat,less,more,tail,head

    Linux 文件内容查看工具介绍 作者:北南南北来自:LinuxSir.Org摘要: 本文讲述几种常用文件内容的查看工具,比如cat.more.less.head.tail等,把这些工具最常用的参数. ...

  8. rails image_tag生成图片标签

    image_tag(source, options={}) Link Returns an HTML image tag for thesource. The source can be a full ...

  9. 面试6 在c#中如何声明一个类不能被继承

    C#通过关键字 sealed 可以声明一个类型不能被继承. 设计中应该为所有不被作为基类的类型添加sealed关键字,用以避免各种来自继承的易产生的错误.

  10. SpringMVC中文件上传

    在SpringMVC中上传文件是比较方便的.主要分为以下几个步骤: 1)在applicationContext.xml中增加相应类的引用 <bean id="multipartReso ...