![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithms problems
木木o-o
这个作者很懒,什么都没留下…
展开
-
排序---小范围排序
问题描述:对一个数组排序,已知数组每个元素的移动距离不超高k,选择最合适的排序方法。解题思路:每个元素移动距离不超过k,说明最小的元素一定在前k个中。可以通过建立一个k个元素的最小堆,依次剔除最小元素,并加入下一个元素,循环此过程。时间复杂度为Nlgk。源码:#include <iostream>#include <vector>using namespace std;...原创 2018-04-07 17:08:37 · 227 阅读 · 0 评论 -
数组---是否包含重复值(1)
问题描述:对一个数组,判断是否包含重复值。解题思路:不考虑空间复杂度时,选择用哈希表。源码:#include <iostream>#include <vector>#include <set>using namespace std;//判断是否包含重复值bool ContainsDuplicate(int * nums,int n){ set&l...原创 2018-04-09 21:32:54 · 163 阅读 · 0 评论 -
最大公约数、最小公倍数
1.两个数的最大公倍数(辗转相除法)#include <iostream>#include <vector>#include <set>using namespace std;//辗转相除法求两数的最大公约数int get_Common_divisor(int a, int b){ int divisor = 1; if (a < b)...原创 2018-04-10 10:26:17 · 129 阅读 · 0 评论 -
数组---旋转数组
问题描述:给定数组A和下标k,输出旋转后的数组。例子:给定[1,2,3,6,7,8] 3输出:[6,7,8,1,2,3]解题思路:首先将整个数组旋转,然后分别旋转两个数组的部分。源码:#include <iostream>using namespace std;void reverse(int * A, int bg, int ed){ while (bg < ed)...原创 2018-04-04 10:13:05 · 999 阅读 · 1 评论