当前位置:网站首页>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函数的功能是元素去重。即“删除”序列中所有相邻的重复元素(只保留一个)
边栏推荐
- Shift Operators
- Crash problem of Chrome browser
- Deep analysis of C language pointer
- LeetCode:387. 字符串中的第一个唯一字符
- 如何有效地进行自动化测试?
- Warning in install. packages : package ‘RGtk2’ is not available for this version of R
- To effectively improve the quality of software products, find a third-party software evaluation organization
- JVM quick start
- LeetCode:剑指 Offer 04. 二维数组中的查找
- Process of obtaining the electronic version of academic qualifications of xuexin.com
猜你喜欢
深度剖析C语言指针
[embedded] print log using JLINK RTT
Warning in install. packages : package ‘RGtk2’ is not available for this version of R
Roguelike游戏成破解重灾区,如何破局?
UML图记忆技巧
Light of domestic games destroyed by cracking
Problems in loading and saving pytorch trained models
LeetCode:498. 对角线遍历
Current situation and trend of character animation
查看局域网中电脑设备
随机推荐
Charging interface docking tutorial of enterprise and micro service provider platform
sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
TDengine 社区问题双周精选 | 第三期
The mysqlbinlog command uses
Current situation and trend of character animation
Niuke winter vacation training 6 maze 2
ROS compilation calls the third-party dynamic library (xxx.so)
LeetCode:498. 对角线遍历
JS native implementation shuttle box
深度剖析C语言数据在内存中的存储
Hutool gracefully parses URL links and obtains parameters
深度剖析C语言指针
TCP/IP协议
[embedded] cortex m4f DSP Library
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
C language double pointer -- classic question type
[embedded] print log using JLINK RTT
After PCD is converted to ply, it cannot be opened in meshlab, prompting error details: ignored EOF
Promise 在uniapp的简单使用
Light of domestic games destroyed by cracking