时间复杂度为O(n)的就地循环移位 (2010年全国计算机统考考研试题)
来源:互联网 发布:centos sftp 编辑:程序博客网 时间:2024/05/08 12:53
#include<iostream>using namespace std;void reverseString(char str[], int left, int right){int i = left;int j = right;char tmp;while(i < j){tmp = str[i];str[i] = str[j];str[j] = tmp;// 用while时一定要注意循环体中的自增或自减i++;j--;}}// 向左循环移动distance位void leftLoopShift(char str[], int distance){int length = strlen(str);reverseString(str, 0, length - 1);reverseString(str, 0, length - distance - 1);reverseString(str, length - distance, length - 1);}int main(){char str[] = "1234567";int distance = 2;leftLoopShift(str, distance);cout << str << endl;return 0;}
- 时间复杂度为O(n)的就地循环移位 (2010年全国计算机统考考研试题)
- 时间复杂度为O(n)的排序
- 时间复杂度为O(n)的排序
- 矩阵就地转置+O(Nlog(N))时间复杂度
- 动态规划求数组中和最大字串的值 以及 字符串的循环移位(要求空间复杂度O(1),时间复杂度O(n))
- 循环右移,要求时间复杂度为O(n)且尽可能的少使用辅助空间
- 面试题7-2:时间复杂度为O(n)的排序
- 时间复杂度为O(n),空间复杂度为O(1)
- 把一个含有N个元素的数组循环右移K位, 要求时间复杂度为O(N)
- 排序的时间复杂度为O(n),空间复杂度为O(1)
- 时间复杂度为O(N),空间复杂度为O(1)的排序算法
- 时间复杂度为O(n+t)的排序
- 时间复杂度为O(n)的排序算法
- 时间复杂度为O(n)的排序算法--计数算法
- 求一个数组的中位数时间复杂度为O(n)
- 面试9:时间复杂度为O(n)的排序算法
- 平均时间复杂度为O(n)的选择算法
- 基于时间复杂度为O(n)的排序算法
- 胡锦涛:扭转生态环境恶化趋势建设美丽中国
- 数组中最小没出现的整数
- 同济大学软件学院院长谈择业—关于嵌入式方向
- Android应用开发揭秘的第12个程序5_7_drawImage修改版和高仿版的源码注释
- 用hadoop中的libhdfs和fuse-dfs构建快速云存储(出自 实践检验真理 博客)
- 时间复杂度为O(n)的就地循环移位 (2010年全国计算机统考考研试题)
- 一个简单的java程序
- 高质量代码的三要素
- 中共承诺让农民得到更多土地增值收益
- HashMap和Hashtable的区别
- 假如我来架构12306网站
- 白话经典算法系列之三 希尔排序的实现
- Xcode运行不了API文档给的代码或是以前的工程
- C++第11周项目2(9)参考——污损的数字