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. tensorflow基础篇-1

    1.使用占位符和变量 import tensorflow as tf import numpy as np #-----创建变量并初始化----------- def first(): my_var= ...

  2. java8新特性-入门摘要

    本文是针对java8做的入门摘要笔录,详细分析可参见如下原文. 原文地址 http://www.javacodegeeks.com/2013/02/java-8-from-permgen-to-met ...

  3. 【数组】Maximum Product Subarray

    题目: Find the contiguous subarray within an array (containing at least one number) which has the larg ...

  4. hexo上部署博客到Github失败

    fatal: could not read Username for 'https://github.com': No error 今天在上传博客到搭建到 Github 的个人博客上的时候,已经使用 ...

  5. Java保存文本文件

    String requestData = "something you want to save"; String saveFilePath = "C:\\Users\\ ...

  6. ruby 数组操作

    数组的创建 arr = Array.new num #创建num个元素的数组,所有数组元素为nil arr = Array.new num, elem #创建num个元素的数组,所有数组元素为elem ...

  7. webstorm皮肤外观样式快速设置,CMD的使用方法,webstorm11激活方法

    一.皮肤外观设置 因为这里是上班时间写的,其客套话就不多bb.步入正题 1.首先设置webstorm整体面板颜色 file->settings->Appearance&Behavi ...

  8. ARM的体系结构与编程系列博客——ARM处理器系列介绍

    ARM处理器系列介绍 现在到了3月,过年过得过于舒服了.系列博客也停更了近半月,我果然是个慢(lan)性(gui)子,那么趁着到校的第一天晚上,就写一篇博客来继续我的系列博客了!众所周知,ARM处理器 ...

  9. [转]SQL SERVER数据库删除LOG文件和清空日志的方案

    本文转自:https://www.cnblogs.com/ShaYeBlog/archive/2012/09/04/2670505.html 数据库在使用过程中会使日志文件不断增加,使得数据库的性能下 ...

  10. 关于EF Unit of Work Repository的简单用法

    其实ef本身就是unit of work+repository的 其中继承自DbContext的类就是unit of work context中的DbSet<T>属性就是repositor ...