当前位置:网站首页>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函数的功能是元素去重。即“删除”序列中所有相邻的重复元素(只保留一个)
边栏推荐
- Revit 二次开发 HOF 方式调用transaction
- Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges
- 深度剖析C语言数据在内存中的存储
- Deep anatomy of C language -- C language keywords
- 企微服务商平台收费接口对接教程
- Esp8266-rtos IOT development
- Function coritization
- 目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
- Simple use of promise in uniapp
- Tcp/ip protocol
猜你喜欢
704 binary search
Nacos 的安装与服务的注册
生成器参数传入参数
vb.net 随窗口改变,缩放控件大小以及保持相对位置
C語言雙指針——經典題型
Esp8266-rtos IOT development
Visual implementation and inspection of visdom
After reading the programmer's story, I can't help covering my chest...
UML圖記憶技巧
Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures
随机推荐
如何有效地进行自动化测试?
Current situation and trend of character animation
LeetCode:498. 对角线遍历
LeetCode:387. 字符串中的第一个唯一字符
生成器参数传入参数
Computer graduation design PHP Zhiduo online learning platform
随手记01
超高效!Swagger-Yapi的秘密
ESP8266-RTOS物联网开发
Roguelike游戏成破解重灾区,如何破局?
egg. JS directory structure
LeetCode:394. 字符串解码
Using pkgbuild:: find in R language_ Rtools check whether rtools is available and use sys The which function checks whether make exists, installs it if not, and binds R and rtools with the writelines
Process of obtaining the electronic version of academic qualifications of xuexin.com
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
Trying to use is on a network resource that is unavailable
[MySQL] limit implements paging
【嵌入式】Cortex M4F DSP库
广州推进儿童友好城市建设,将探索学校周边200米设安全区域
【ROS】usb_ Cam camera calibration