
0x10 基本数据结构
文章平均质量分 50
ACW题目
常欢愉皆胜意且顺遂
记得一定要努力,不然往后余生,做饭是你,洗衣是你,做家务是你……是你是你还是你
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
leetcode 234. 回文链表
题目传送门 链接:https://leetcode-cn.com/problems/palindrome-linked-list/ 题干 题解 可以先把链表的值记录在一个数组内,再判断这个数组是否是回文即可 Code /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {}原创 2021-03-19 11:02:42 · 180 阅读 · 1 评论 -
leetcode 92. 反转链表 II
题目传送门 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/reverse-linked-list-ii 题干 题解 刚刚做完一道翻转链表,趁热打铁,把这道题也做了 还是使用两个指针变量,pre 和 cur 来记录前驱节点和当前节点 1、先进行右移,直到 cur 为 left 节点 2、再把 left 和 right 范围内的节点指针进行反转 因为最后需要更改这些指针的指向,我用到了四个指针 p1、p2、p3、p4,来记录 left-1 号节点、le原创 2021-03-18 21:20:50 · 133 阅读 · 0 评论 -
leetcode 206. 反转链表
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/reverse-linked-list 反转一个单链表。 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 进阶: 你可以迭代或递归地反转链表。你能否用两种方法解决这道题? 解法: 需要将链表每个节点的指针进行翻转 首先需要两个指针变量:前驱节点 pre、当前节点 cur 因为需要把当前节点原创 2021-03-18 19:57:46 · 139 阅读 · 0 评论 -
Manacher算法模板
题目二 Manacher算法详解与应用 1.复杂度:O(N) 2.概念: 回文直径:以i为中心,两边能够扩展到的 回文半径:以i为中心,一边能够扩展到的 1)回文半径数组(arr) 记录每个位置的回文半径 2)最右回文右边界® 表示到目前为止在向右扩展时,能到达的最右边的位置。初始为-1 3)回文右边界的中心© 表示第一次到达此右边界的位置 3.马拉车算法的扩展情况(有两种可能性,分成了4种情况,...原创 2019-07-10 17:50:54 · 301 阅读 · 0 评论 -
KMP面试题
# 一道例题(京东2018测试开发工程师笔试编程题) ## 题目描述: 给定一个字符串s,请计算输出含有连续两个s作为子串的最短字符串。注意两个s可能有重叠部分。例如,"ababa"含有两个"aba"。 ## 输入描述: 输入包括一个字符串s,字符串长度length(1 ≤ length ≤ 50),s中每个字符都是小写字母。 ## 输出描述: 输出一个字符串,即含有连续两个s作为子串的最短字符串。原创 2019-07-09 16:44:47 · 435 阅读 · 1 评论 -
kuangbin带你飞 KMP专题
Given two sequences of numbers : a[1], a[2], … , a[N], and b[1], b[2], … , b[M] (1 <= M <= 10000, 1 <= N <= 1000000). Your task is to find a number K which make a[K] = b[1], a[K + 1] = b[2...原创 2019-05-03 19:06:08 · 394 阅读 · 0 评论 -
KMP算法模板
#include <bits/stdc++.h> using namespace std; const int N = 1e6; int Next[N + 5]; char s1[N + 5], s2[N + 5]; int len1, len2; void get_next() { int i, j; i = 0; Next[0] = j = -1; ...原创 2019-05-03 16:55:12 · 154 阅读 · 0 评论 -
F - Power Strings(kmp)
Description Given two strings a and b we define ab to be their concatenation. For example, if a = “abc” and b = “def” then ab = “abcdef”. If we think of concatenation as multiplication, exponentiation...原创 2019-07-26 17:26:11 · 369 阅读 · 0 评论 -
E - Period(kmp)
Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, fo...原创 2019-07-25 23:02:51 · 296 阅读 · 0 评论 -
G - Seek the Name, Seek the Fame(kmp)
The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such boring job, the inn原创 2020-09-24 20:12:05 · 386 阅读 · 0 评论 -
J - Count the string(kmp)
It is well known that AekdyCoin is good at string problems as well as number theory problems. When given a string s, we can write down all the non-empty prefixes of this string. For example: s: “abab” The prefixes are: “a”, “ab”, “aba”, “abab” For each pre原创 2020-09-24 22:01:28 · 187 阅读 · 0 评论 -
D - Cyclic Nacklace(kmp)
Input The first line of the input is a single integer T ( 0 < T <= 100 ) which means the number of test cases. Each test case contains only one line describe the original ordinary chain to be r...原创 2019-05-04 17:12:56 · 306 阅读 · 0 评论 -
单调栈简介及代码模板
单调栈简介 单调栈,栈内的元素要从小到大,或者从大到小 如果一个栈是单调递增的,要求从栈顶到栈底单调递增: 当要进栈的元素 x 大于栈顶元素时,需要先弹出所有比 x 小的元素,再将 x 压入栈 当要进栈的元素 x 小于栈顶元素时,直接将 x 压入栈 while (stk.size() && x > stk.top()) { stk.pop(); } stk.push(x); P5788 【模板】单调栈 题目链接:https://www.luogu.com.cn/problem/P5原创 2020-10-04 10:35:15 · 385 阅读 · 0 评论 -
字典树(Trie)模板
字典树是一种用于字符串快速索引的树结构。 字典树最基础的应用——查找一个字符串是否在“字典”中出现过。 #include <iostream> #include <cstring> using namespace std; const int N = 1e6 + 5; int trie[N][26], tot = 1;//初始化 bool exist[N];//以该结点结尾的字符串是否存在 char str[N]; void i...原创 2020-01-27 17:41:59 · 338 阅读 · 0 评论 -
Trie
142. 前缀统计 #include <iostream> #include <cstring> using namespace std; const int N = 1e6 + 5; int trie[N][26], tot = 1;//初始化 int exist[N]; char str[N]; void insert(char* str)//插入一个字符串 ...原创 2020-01-27 17:24:24 · 184 阅读 · 0 评论 -
二叉堆
148. 合并果子 #include <iostream> #include <queue> using namespace std; priority_queue<int, vector<int>, greater<int> > que; int main(void) { int n, t, a, b, ans = 0; c...原创 2020-01-27 13:52:23 · 2710 阅读 · 0 评论 -
队列
132. 小组队列 输入样例: 2 3 101 102 103 3 201 202 203 ENQUEUE 101 ENQUEUE 201 ENQUEUE 102 ENQUEUE 202 ENQUEUE 103 ENQUEUE 203 DEQUEUE DEQUEUE DEQUEUE DEQUEUE DEQUEUE DEQUEUE STOP 2 5 259001 259002 259003 2...原创 2020-01-26 21:05:40 · 402 阅读 · 0 评论 -
栈
41. 包含min函数的栈 不太清楚C++的语法T^T 这道题因为要实现一个O(1)复杂度的getMin函数,可以另外开一个栈来存储前 i 位最小的值 class MinStack { public: /** initialize your data structure here. */ stack<int> stk, min_stk; MinSta...原创 2020-01-20 16:34:48 · 291 阅读 · 0 评论 -
字符串
141. 周期 当i-next[i]能整除i时,S[1~i-next[i]]就是S[1~i]的最小循环元,它的最大循环次数就是i/(i-next[i]) #include <bits/stdc++.h> using namespace std; const int N = 1e6; int Next[N + 5]; char s2[N + 5]; int len1, len2; ...原创 2020-01-15 19:53:45 · 192 阅读 · 0 评论 -
AcWing 826. 单链表
题目 实现一个单链表,链表初始为空,支持三种操作: (1) 向链表头插入一个数; (2) 删除第k个插入的数后面的数; (3) 在第k个插入的数后插入一个数 现在要对该链表进行M次操作,进行完所有操作后,从头到尾输出整个链表。 注意: 题目中第k个插入的数并不是指当前链表的第k个数。例如操作过程中一共插入了n个数,则按照插入的时间顺序,这n个数依次为:第1个插入的数,第2个插入的数,…第n个插入的...原创 2019-07-08 11:19:51 · 467 阅读 · 0 评论 -
哈希
很久很久以前,森林里住着一群兔子。 有一天,兔子们想要研究自己的 DNA 序列。 我们首先选取一个好长好长的 DNA 序列(小兔子是外星生物,DNA 序列可能包含 26 个小写英文字母)。 然后我们每次选择两个区间,询问如果用两个区间里的 DNA 序列分别生产出来两只兔子,这两个兔子是否一模一样。 注意两个兔子一模一样只可能是他们的 DNA 序列一模一样。 输入格式 第一行输入一个 DNA 字符串...原创 2019-08-05 22:37:47 · 363 阅读 · 0 评论