3月份的每日一题活动 使用队列实现栈的下列操作: push(x) -- 元素 x 入栈pop() -- 移除栈顶元素top() -- 获取栈顶元素empty() -- 返回栈是否为空注意: 你只能使用队列的基本操作-- 也就是 push to back, peek/pop from front, s ...
分类:
其他好文 时间:
2020-03-01 20:10:06
阅读次数:
77
int main() { vector<int> a; a.push_back(1); a.push_back(2); for (auto &i : a) // 加上引用是安全的写法 { i = 3; cout << i << endl; } for (auto i:a) { cout << i < ...
分类:
其他好文 时间:
2020-02-24 09:57:24
阅读次数:
82
题目描述首先明确一下题意,先输入两个整数n、m,n代表在区间[-1e9,1e9]某一点加一个整数的次数,输入x c在x处加上c,m代表求某个区间和的次数,输入l r求区间[l,r]的和。 分析分析一下y总的代码。 主要分为5大步:1.读输入。将每次读入的x c push_back()到add中,将每 ...
//坑点一,序号不存在,表示序号可能大于最大值,或者小于最小值。 //坑点二,输出转义字符\,用\\ 注意点:二维数组vvs,只能插入一维数组vs,不能直接通过语法vvs[i].push_back(str)实现粒度插入。 #include<iostream> #include<vector> usi ...
分类:
其他好文 时间:
2020-02-22 13:48:28
阅读次数:
70
题目 定义一个函数,输入一个链表的头节点,反转该链表并输出反转后链表的头节点。 示例: 限制: `0 res; ListNode pNode = head; while (pNode != nullptr) { res.push_back(pNode val); pNode = pNode next ...
分类:
其他好文 时间:
2020-02-21 23:57:14
阅读次数:
117
一、vector动态数组 用法: 尾部添加:push_back() 元素个数:size() 是否为空:empty() 在第i个元素前面插入k:insert(a.begin()+i,k) 删除尾部元素:pop_back() 删除区间:eraser(a.begin()+i,a.begin()+j) 删除 ...
分类:
其他好文 时间:
2020-02-14 16:40:34
阅读次数:
63
单调队列分为递增队列和递减队列,一般用来求某个固定长度(例如:滑动窗口的最值)序列中的最大/最小值。 对于递增队列,队首元素就是最小值。 对于递减队列,队首元素就是最大值。 1.递增队列(队列首尾最小值) if(q.empty()) q.push_back(A[i]); else if(q.back ...
分类:
其他好文 时间:
2020-02-09 14:33:49
阅读次数:
83
9.18 - 9.22 //***********9.3.1节练习 9.18************** string temp; deque<string> sdeq;//默认初始化 while (cin >> temp) { sdeq.push_back(temp); } for (auto i ...
分类:
编程语言 时间:
2020-02-06 15:04:06
阅读次数:
83
链表list 建立 头文件<list> list<string>l; list<int>l(8,0); vector<int>v; list<int>l(v.begin(),v.end()); 操作 插入 l.push_back(a);——在链表的后面添加元素 l.push_front(a);——在 ...
分类:
编程语言 时间:
2020-02-05 17:59:30
阅读次数:
80
题目链接 Code: 1 class Solution { 2 public: 3 int maxCoins(vector<int>& nums) { 4 vector<int> arr; 5 arr.push_back(1); 6 for(int i:nums){ 7 arr.push_back( ...
分类:
其他好文 时间:
2020-02-01 16:44:57
阅读次数:
56