11 2021 档案
摘要:##排序从大到小 priority_queue<int,vector<int>,greater<int> >q; ##堆排序 #include <iostream> #include <algorithm> using namespace std; const int N = 100010; int
阅读全文
摘要:报错no viable overloaded '='; ``` ListNode f=head,s=head; while(k--) f=f.next;//你试图用一个f结构体接收指针 ``` 报错non-void function does not return a value in all ``
阅读全文
摘要:比map o (logn)查的更快的hash——map o(1),但不一定,且增加一点内存, 但c++没有提供给这个模板, ##关于基本语法 map.insert( , ); map.count(key)//找map是否存过这个东西,有的话返回1,没有返回0,因为map只有一个 map.find(k
阅读全文
摘要:##反转链表 public: ListNode* reverseList(ListNode* head) { // 1. 递归终止条件 if (head == nullptr || head->next == nullptr) return head;//最后一个是p //注意上面的顺序不能调换!否
阅读全文
摘要:这个直接能代表数组里面的元素 for (int x: nums); ###作用就是迭代容器中所有的元素,每一个元素的临时名字就是x,等同于下边代码,但需要加*号 for (vector<int>::iterator iter = nums.begin(); iter != nums.end(); i
阅读全文
摘要:#首先理解 比如一个链表是这样的:let aaa = [1, 2, 3, 4] 那么 aaa.val 1 aaa.next [2, 3, 4]; aaa.next.val 2 ##将vector里的元素一次遍历放到里,构建链表 //当容器存的是结点的时候 vector<ListNode*>a; Li
阅读全文
摘要:##将vector元素放到set中 class Solution { public: bool containsDuplicate(vector<int>& nums) { unordered_set<int> s(nums.begin(), nums.end()); return s.size()
阅读全文