LeetCode
2Ululu
这个作者很懒,什么都没留下…
展开
-
python3记忆化的方法
Leetcode python记忆化原创 2022-07-03 19:01:45 · 341 阅读 · 1 评论 -
LeetCode 370 线段树懒标记板子
线段树维护区间和原创 2022-06-04 23:56:54 · 233 阅读 · 0 评论 -
LeetCode 699 线段树懒标记之动态开点(c++)
class Node {public: Node* left; Node* right; int l; int r; int mid; int v; int add; Node(int l, int r) { this->l = l; this->r = r; this->mid = (l + r) >> 1; this->left = th.原创 2022-05-27 18:06:49 · 275 阅读 · 0 评论 -
Leetcode 433. 最小基因变化 「BFS」&「双向 BFS」
BFSclass Solution: def minMutation(self, start: str, end: str, bank: List[str]) -> int: s,bank=set(),set(bank) if start==end:return 0 q=deque() q.append((start,0)) s.add(start) while q:原创 2022-05-07 11:33:03 · 322 阅读 · 0 评论 -
Leetcode LCP 52. 二叉搜索树染色 珂朵莉树模板题
typedef long long ll;struct ChthollyTree{ struct node { ll l, r; mutable ll v; node(ll l, ll r, ll v) : l(l), r(r), v(v) {} bool operator<(const node &o) const { return l < o.l; } }; set<node...原创 2022-04-17 23:28:00 · 435 阅读 · 3 评论 -
Leetcode 952. 按公因数计算最大组件大小 C++并查集模板
这个代码是在评论区copy大佬的,觉得写的很不错了,借鉴了!class Solution { class UnionFind { public: vector<int> parent; vector<int> size; int n; UnionFind(int _n): n(_n), parent(_n), size(_n, 0) { iota(parent.begi原创 2022-04-13 15:43:45 · 1068 阅读 · 0 评论 -
LeetCode1649. 通过指令创建有序数组 C++ 树状数组和线段树
树状数组template <class T> class FenwickTree { int limit; vector<T> arr; //树状数组是从1开始储存的,而不是0 inline int lowbit(int x) { return x & (-x); }public: FenwickTree(int limit=1) { this->limit = limit; arr =原创 2022-04-08 10:22:51 · 423 阅读 · 0 评论 -
Leetcode1606 找到处理最多请求的服务器(线段树解法)
分析:将编号为0,1,..k-1,的k个服务器开始空闲的时间记做time[t],0<=t<k,刚开始所有的time都为0对于一个arrival[i],令x=i%k,我们想要知道以j= x,x+1,...,k-2,k-1,0,1,...,x-2,x-1顺序下的第一个j,使得time[j]<=arrival[i],可以发现[x,k-1]为一个连续的区间,[0,x-1]也是一个连续的区间。相当于在服务器中先查询[x,k-1]区间,如果找到直接返回;否则再查询[0,x-1]区间。这样就能够原创 2022-03-30 14:24:17 · 368 阅读 · 0 评论 -
Leetcode 2213 由单个字符重复的最长子字符串(线段树)
根据题目要求设计线段树节点内的信息只需要pushup,不需要pushdown所以不需要使用懒标记,其中qurry函数也是多余的,但是此份代码主要是为了记录一个线段树的模板class Solution { static const int N = 1e5 ; string s; struct TreeNode { int l, r, size; char lc, rc; int lmax, rmax, dmax; } t原创 2022-03-24 23:03:35 · 478 阅读 · 0 评论 -
leetcode 256 场周赛 自己犯的nc错
第二题:5855. 找出数组中的第 K 大整数C++这样写sort自定义排序怎么写编译多过不了,而且还一直发现不了自己的问题class Solution {public: bool cmp(string a,string b){ int n1=a.size(),n2=b.size(); if(n1!=n2) return n1<n2; else return a<b; } string k原创 2021-08-29 14:07:44 · 88 阅读 · 0 评论 -
LeetCode 179. 最大数 python3解法(自定义比较实例)
题目链接:https://leetcode-cn.com/problems/largest-number/cmp想要实现的目的都是从大到小降序排列注意:C++和python的逻辑是相反的python中:s1>s2 返回的是-1s1<s2 返回的是1C++中:s1>s2 返回的是trueelse 返回的是falsepython代码:def cmp(a,b): s1=str(a)+str(b) s2=str(b)+...原创 2021-04-12 12:31:27 · 252 阅读 · 0 评论 -
自定义结构体的哈希函数解决337. 打家劫舍 III
unordered_map<node,int,hashNode,cmpNode> mp;node 为key,int为value,hashNode为自定义结构体的哈希函数(unordered_map就是通过这个值去查找的)cmpNode比较函数(如果哈希值相同,怎么去处理不同的对象,也就是怎么解决冲突)/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNod原创 2021-02-04 11:33:56 · 756 阅读 · 0 评论