Divide a list of numbers into group of consecutive numbers
来源:互联网 发布:php手机社区源码 编辑:程序博客网 时间:2024/06/05 03:01
//Divide a list of numbers into group of consecutive numbers but their original order should be preserved?
//8,2,4,7,1,0,3,6
//2,4,1,0,3 and 8,7,6
//obviously in shortest time and space.
我想到的方法比较土,用set存储所有的值。用iteration 指针变量set中的值,这肯定是有序的,就可以将有序的数字分组。
更为直接的方法就是,先对数组排序,即可
有更快的算法:
定义一个bool a[n],记录 数组中的数字是否被处理过。
用map<int,int>记录key 和 index的值
从左到右依次处理在a中表明未被访问过的数字,并-1或者+1向左右扩展,通过查询map来确定数组是否存在,并将a中对应的下标设为已访问。
- Divide a list of numbers into group of consecutive numbers
- Array into ranges of consecutive numbers
- A - Sum of Consecutive Prime Numbers
- A - Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- making a list of numbers vim
- CF850B-Arpa and a list of numbers
- CF_850B Arpa and a list of numbers
- A sequence of numbers
- A sequence of numbers
- A sequence of numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- vs2010鼠标进行代码拖拽操作时会出现异常
- android AsyncTask介绍
- C and C++ call
- 性能测试脚本录制时协议选择参考
- 到底什么是创意?
- Divide a list of numbers into group of consecutive numbers
- php之递归调用,递归创建目录
- gcc前端的基本结构
- PHP生成GUID
- OpenWRT移植到三星S5PV210处理器上
- MVC 4.0下的首页验证码功能实现
- 从30岁到35岁:为你的生命多积累一些厚度
- Eclipse-"File Search" has encounter a problem
- Android客户端WebService访问接口(Ksoap2Android调用.net服务端)