当前位置:网站首页>Leetcode刷题题解2.1.1
Leetcode刷题题解2.1.1
2022-07-06 08:49:00 【好久不见0327】
distance()函数用于计算两个迭代器表示的范围内包含元素的个数
template<class Inputlterator>
typename iterator_traits<Inputlterator>::difference_type distance(Inputlterator first, Inputlterator last);#include<iostream>
#include<iterator>
#include<list>
using namespace std;
int main() {
// 创建一个空list容器
list<int> mylist;
// 向空的list容器中添加元素0~9
for (int i = 0; i < 10; i++) {
mylist.push_back(i);
}
// 指定2个双向迭代器,用于执行某个区间
list<int>::iterator first = mylist.begin(); // 指向元素0
list<int>::iterator last = mylist.end(); // 指向元素9之后的位置
// 获取[first, last)范围内包含元素的个数
cout << "distance() = " << distance(first, last);
return 0;
}unique函数的功能是元素去重。即“删除”序列中所有相邻的重复元素(只保留一个)
边栏推荐
猜你喜欢
随机推荐
Tdengine biweekly selection of community issues | phase III
Roguelike游戏成破解重灾区,如何破局?
使用latex导出IEEE文献格式
[MySQL] limit implements paging
JS native implementation shuttle box
项目连接数据库遇到的问题及解决
View computer devices in LAN
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
To effectively improve the quality of software products, find a third-party software evaluation organization
LeetCode:673. 最长递增子序列的个数
The mysqlbinlog command uses
JVM quick start
TDengine 社区问题双周精选 | 第三期
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
LeetCode:836. 矩形重叠
visdom可视化实现与检查介绍
深度剖析C语言数据在内存中的存储
Leetcode: Sword Finger offer 42. Somme maximale des sous - tableaux consécutifs
The harm of game unpacking and the importance of resource encryption
LeetCode:162. 寻找峰值





![[MySQL] multi table query](/img/eb/9d54df9a5c6aef44e35c7a63b286a6.jpg)



