01 2019 档案
摘要:``` class Solution { public: //startFuel的含义是我们的车能开的距离,如果startFuel target,那么一次加油也不需要直接开到重点 int minRefuelStops(int target, int startFuel, vector &statio
阅读全文
摘要:有一个圈圈的是RX,然后从左往右依次是rx tx gnd vcc
阅读全文
摘要:方法一 二叉排序树 将传入数组 依次插入二叉排序树中,每个节点由val(元素值) , count (元素出现次数) , left_count(比这个元素小的元素个数),插入完成后 依次查询完成答案 以1 2 9 2 3 1 7为例 插入过程 若待插入值比当前节点值小,当前节点left_count+=
阅读全文
摘要:树状数组 一.为什么需要树状数组? 举一个简单的例子,假设有一个数组 我们需要实现两个功能: 1.计算数组任意X~X+N项元素的和 2.能够动态的增删改节点 有两种解决方法: 1.将数组直接存储下来 此时,求X~X+N的和时间复杂度是O(N) 修改并维护数组的时间复杂度是O(1) 2
阅读全文
摘要:a b mod p可以转换为 (a+a+a+a+.......+a) mod p 即为处理 a 2a 4a 8a .......... include using namespace std; int main(){ long long a,b,p; cin a b p; long long ans
阅读全文
摘要:a^b 基础知识 求模就是取余 代码原理 例 3 ^ 7 mod 5 7 = 111 3 ^ 7 = 3^(111) = (3^001) (3^010) (3^100) = (3^1) (3^2) (3^4) 而 3 ^ 001 = 3 ^ 1 = 3 3 ^ 010 = (3 ^ 1)^2 = 9
阅读全文
摘要:``` class Solution { public: void print_board(const vector &ch) { int _pos = 0; cout &board, vector &ch, int x, int y, int n) { constexpr static int d
阅读全文
摘要:78 子集 解法一.位运算 对于一个大小为m的数组,他共有2^m种组合,也就是有2^m个子集 例如 nums = [1,2,3] 那么他的子集则为 而我们知道任何一个整数的二进制表示是唯一的,所以我们可以利用这个特性解决这道题 例如 nums的大小为3,所以易知nums会有 2^3 =8个子集,我们
阅读全文
摘要:```c++ ListNode *merge(ListNode *l, ListNode *r) { auto *pRes = new ListNode(0); ListNode *temp = pRes; while (l != nullptr && r != nullptr) { if (l->val val) { temp->n...
阅读全文
摘要:```c++ vector splitListToParts(ListNode *root, int k) { vector vec; if (root == nullptr) { for (; k > 0; --k) vec.push_back({}); return vec; } int len =...
阅读全文
摘要:```c++ Node *flatten(Node *head) { Node *it = head; stack stack1; while (it) { if (it->child) { stack1.push(it->next); it->next = it->child; ...
阅读全文
摘要:```c++
ListNode *reverse(ListNode *head) { ListNode *front = head, *rear = nullptr, *temp = nullptr; while (front != nullptr) { temp = front->next; front->next = rear; ...
阅读全文
摘要:```c++ ListNode *insertionSortList(ListNode *head) { if (head == nullptr || head->next == nullptr) return head; auto *prehead = new ListNode(0), *front = prehead; prehead->next = h...
阅读全文
摘要:方法一 活用set 方法二 快慢指针找中点然后反转后半部分链表,然后插入到前半个链表当中去
阅读全文
摘要:```c++
TreeNode *BST(ListNode *begin, ListNode *end) { if (begin == end) return nullptr; ListNode *fast = begin, *slow = begin; while (fast->next != end) { fast = fast->nex...
阅读全文