diff --git a/.gitignore b/.gitignore index 91a1cd5c8fb79accc01aaaa15a70220e157e3690..7748e44db191d10b4c42c2a2612dd7d1684a14ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1,2 @@ - -# 项目排除路径 -/cmake-build-debug/ -/*/cmake-build-debug/ - -.Archive/ -.markeditor/ -.markdown/ -.sync/ -.idea/ -.DS_STORE -Thumbs.db* -/.posts_info.json -/posts_info.json -/.git_settings.json -/git_settings.json -/.ios_file_manager_status*.json -/.farbox_token.* -/.farbox_auto_sync.* -/__wechat.json -/*.sqlite3 -.db/ -.configs/ -*/.metion/ -*/_image - -!.metion/ -.metion/* -!.metion/*_sort.config -/.obsidian/ +.obsidian +.idea \ No newline at end of file diff --git "a/DS/2.LinearList/2.1\351\241\272\345\272\217\350\241\250\345\256\232\344\271\211.html" "b/DS/2.LinearList/2.1\351\241\272\345\272\217\350\241\250\345\256\232\344\271\211.html" index 2119af92e205cbafde1e0d56ad947e75ac825ce9..265870b28d600e2eaeffbf16ca0a84f413a7ebe4 100644 --- "a/DS/2.LinearList/2.1\351\241\272\345\272\217\350\241\250\345\256\232\344\271\211.html" +++ "b/DS/2.LinearList/2.1\351\241\272\345\272\217\350\241\250\345\256\232\344\271\211.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ @media print { @page {margin: 0 0 0 0;} body.typora-export {padding-left: 0; padding-right: 0;} #write {padding:0;}} diff --git "a/DS/2.LinearList/2.2\351\241\272\345\272\217\350\241\250\347\232\204\345\256\236\347\216\260.html" "b/DS/2.LinearList/2.2\351\241\272\345\272\217\350\241\250\347\232\204\345\256\236\347\216\260.html" index 2ce26b63d3d244d6456a922804a075ae9a8432dc..2ca94448737b1debd1a7e16d169585f979526c9c 100644 --- "a/DS/2.LinearList/2.2\351\241\272\345\272\217\350\241\250\347\232\204\345\256\236\347\216\260.html" +++ "b/DS/2.LinearList/2.2\351\241\272\345\272\217\350\241\250\347\232\204\345\256\236\347\216\260.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ @media print { @page {margin: 0 0 0 0;} body.typora-export {padding-left: 0; padding-right: 0;} #write {padding:0;}} diff --git "a/DS/2.LinearList/3.3\345\217\214\351\223\276\350\241\250.html" "b/DS/2.LinearList/3.3\345\217\214\351\223\276\350\241\250.html" index 0c8fc78e6adebc12c678679a1dd739fde6f0c44f..c4b6b1abd9b398d46f8a5ed935c8028376a06d8b 100644 --- "a/DS/2.LinearList/3.3\345\217\214\351\223\276\350\241\250.html" +++ "b/DS/2.LinearList/3.3\345\217\214\351\223\276\350\241\250.html" @@ -821,30 +821,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ @media print { @page {margin: 0 0 0 0;} body.typora-export {padding-left: 0; padding-right: 0;} #write {padding:0;}} diff --git a/DS/2.LinearList/code_question/LinkList.h b/DS/2.LinearList/code_question/LinkList.h deleted file mode 100644 index 9042206739e4214cf8d603b17d9901710e6a0ddc..0000000000000000000000000000000000000000 --- a/DS/2.LinearList/code_question/LinkList.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// Created by 渠继旺 on 2023/3/18. -// -// 此文件是链表公用头文件,定义了基础链表和打印链表的方法,结构同LeetCode链表结点 -// -#include -#include -using namespace std; - -struct ListNode { - int val; - ListNode *next; - ListNode() : val(0), next(nullptr) {} - ListNode(int x) : val(x), next(nullptr) {} - ListNode(int x, ListNode *next) : val(x), next(next) {} -}; - -ostream& operator<<(ostream& os, ListNode* lp) { - ListNode* cur = lp; - while (cur != nullptr) { - os << cur->val << " -> "; - cur = cur->next; - } - os << "∅"; - return os << endl; -} diff --git a/DS/2.LinearList/code_question/M_Search.h b/DS/2.LinearList/code_question/M_Search.h new file mode 100644 index 0000000000000000000000000000000000000000..42a6b276b153495ab24707643ee322a654c05a05 --- /dev/null +++ b/DS/2.LinearList/code_question/M_Search.h @@ -0,0 +1,59 @@ +// +// Created by Tippy on 2023/10/21. +// +#include +#include + +using namespace std; + +class Solution { +public: + int M_Search(int A[], int B[], int L) { + int s1, d1, m1, s2, d2, m2; + s1 = 0; + d1 = L - 1; + s2 = 1; + d2 = L - 1; + while (s1 != d1 || s2 != d2) { + m1 = (s1 + d1) / 2; + m2 = (s2 + d2) / 2; + if (A[m1] == B[m2]) return A[m1]; + if (A[m1] < B[m2]) { + s1 = m1 + (s1 + d1) % 2; // 需要考虑元素个数奇偶,保持两个子数组元素个数相等,(s1+d1)%2为1时,说明元素个数为奇数,此时s1=m1+1,否则就是s1=m1 + d2 = m2; + } else { + d1 = m1; + s2 = m2 + (s2 + d2) % 2; + } + } + return A[s1] < B[s2] ? A[s1] : B[s2]; // 三元表达式, 与下面的if else等价 + // if (A[s1] < B[s2]) + // return A[s1]; + // else + // return B[s2]; + } + + int M_Search1(int A[], int B[], int L) { + // 次优解,时间复杂度O(L) + // 使用两个指针(数组角标)分别指向A和B, 每次比较两个指针指向的数, 小的那个指针向后移动一位 + // 直到两个指针共移动了L次, 下一次移动的指针移动后指向的数就两个数组的中位数(因为题目要求是向上取整) + int p1 = -1, p2 = -1; + for (int i = 0; i < L; ++i) { + if (B[p2 + 1] < A[p1 + 1]) + p2++; + else + p1++; + } + + return B[p2 + 1] < A[p1 + 1] ? B[p2 + 1] : A[p1 + 1]; + } +}; + +int TestModule() { + int A[] = {1, 3}; + int B[] = {2, 4}; + Solution s = Solution(); + cout << "中位数为:"; + cout << s.M_Search(A, B, 2); + return 1; +} \ No newline at end of file diff --git a/DS/2.LinearList/code_question/findSuffix.h b/DS/2.LinearList/code_question/findSuffix.h new file mode 100644 index 0000000000000000000000000000000000000000..e5adcb36363c969c8dd915b775da234ca97c9923 --- /dev/null +++ b/DS/2.LinearList/code_question/findSuffix.h @@ -0,0 +1,106 @@ +// +// Created by Tippy on 2023/10/25. +// +#include "linklist.h" + +class Solution { +public: + int listlen(ListNode *head) { // 求链表长度 + int len = 0; + while (head->next != NULL) { + len++; + head = head->next; + } + return len; + } + + ListNode *findSuffix(ListNode *str1, ListNode *str2) { + // 408答案 + // 时间复杂度O(m+n),空间复杂度O(1) + int m, n; + ListNode *p, *q; + m = listlen(str1); // 求str1的长度.O(m) + n = listlen(str2); // 求str2的长度.O(n) + for (p = str1; m > n; m--) // 使p指向的链表与q指向的链表长度相等. + p = p->next; + for (q = str2; m < n; n--) // 使q指向的链表与p指向的链表长度相等. + q = q->next; + + while (p->next != NULL && p->next != q->next) { // 查找共同后缀的起始点 + p = p->next; + q = q->next; + } + return p->next; // 返回共同后缀的起始点 + } + + ListNode *findSuffix1(ListNode *str1, ListNode *str2){ + // LeetCode上看到的最优解 + // 设A的长度为a+c,B的长度为b+c;其中c为A、B的公共部分长度 + // 拼接AB、BA:A+B=a+c+b+c B+A=b+c+a+c;由于a+c+b=b+c+a,因此二者必定在c的起始点处相遇 + // 时间复杂度O(m+n),空间复杂度O(1) + ListNode *p1=str1,*p2=str2; + + while (p1!=p2){ + p1=p1==nullptr?str2:p1->next; + p2=p2==nullptr?str1:p2->next; + } + return p1; + } + + ListNode *reverse(ListNode *l) { // 反转链表 + ListNode *nl = (ListNode *) malloc(sizeof(ListNode)); + ListNode *p = l; + while (p->next) { + ListNode *n = (ListNode *) malloc(sizeof(ListNode)); + n->val = p->next->val; + n->next = nl->next; + nl->next = n; + p = p->next; + } + return nl; + } + + ListNode *findSuffix2(ListNode *str1, ListNode *str2) { + // 将两个链表反转存放在p1和p2(题目未要求空间复杂度) + // 从头开始遍历两个链表, 直到遇到下一个结点值不相等的结点, 此时的结点就是两个链表的第一个公共结点,但由于不是原来链表的结点,所以不能直接返回 + // 将p和p1同步后移(因为p1是反转后的链表,所以p1到结尾处时p会到第一个公共结点处)直到p1为空,返回p + // 时间复杂度O(m+n),空间复杂度O(m+n) + ListNode *p1 = reverse(str1), + *p2 = reverse(str2), + *p = str1; + while (p1->next && p2->next && p1->next->val == p2->next->val) { + p1 = p1->next; + p2 = p2->next; + } + while (p1) { + p = p->next; + p1 = p1->next; + } + return p; + } +}; + + +int TestModule() { + ListNode *str1 = new ListNode(), + *str2 = new ListNode(), + *cur1 = str1, + *cur2 = str2; + for (auto &i: {4, 1, 8, 4, 5}) { + cur1->next = new ListNode(i); + cur1 = cur1->next; + } + for (auto &i: {5, 6, 1, 8, 4, 5}) { + cur2->next = new ListNode(i); + cur2 = cur2->next; + } + Solution s = Solution(); + cout << "输入链表1为:\n"; + cout << str1; + cout << "输入链表2为:\n"; + cout << str2; + ListNode *res = s.findSuffix(str1, str2); + cout << "输出结果为:\n"; + cout << res; + return 1; +} \ No newline at end of file diff --git "a/DS/2.LinearList/\344\273\243\347\240\201\351\242\230.html" "b/DS/2.LinearList/\344\273\243\347\240\201\351\242\230.html" index 2695b4d75f04b349d8b6563e9516999093168008..80e23e042b4678ac70eef17c9c3ef2d6ffd8bde8 100644 --- "a/DS/2.LinearList/\344\273\243\347\240\201\351\242\230.html" +++ "b/DS/2.LinearList/\344\273\243\347\240\201\351\242\230.html" @@ -4,13 +4,458 @@ 代码题
-

代码运行可以参考根目录下README.md中的程序调试和main.cpp

题目标题不能直接跳转,需要把项目拉到本地用编译器打开后才能跳转,或者去仓库里找对应路径的代码文件

1.合并有序链表

将两个递增的有序链表合并为一个递增的有序链表。要求结果链表仍使用原来两表的存储空间,不另外占用其他的存储空间。表中不允许有重复的数据。

输入:

1
2
4
1
3
4

输出:

1
2
3
4

 

 

2.求两链表交集

已知两个链表A和B分别表示两个集合,其元素递增排列。请设计一个算法,用于求出A与B的交集,并将结果存放在A链表中。

输入:

1
2
3
4
5
6
7
2
3
5
7

输出:

2
3
5
7

 

7.数组左移

2010年真题

设将n(n>1)个整数存放到一维数组R中。试设计一个在时间和空间两方面都尽可能高效的算法。将R中保存的序列循环左移p(0<p<n)个位置,即将R中的数据由(X0,X1,...,Xn-1)变换为(Xp,Xp+1,...,Xn-1,X0,X1,...,Xp-1)。 要求:

  1. 给出算法的基本设计思想。

  2. 根据设计思想,采用C或C++语言描述算法,关键之处给出注释。

  3. 说明你所设计算法的时间复杂度和空间复杂度。

解答:

  1. 可以将这个问题视为把数组ab转换成数组ba(a代表数组的前p个元素,b代表数组中余下的n-p个元素),先将a逆置得到a-1b, 再将b逆置得到a-1b-1 -最后将整个a-1b-1逆置得到(a-1b-1)-1 = ba。

    设Reverse函数执行将数组元素逆置的操作,对abcdefgh向左循环移动3(p=3)个位置的过程如下:

    注: Reverse中, 两个参数分别表示数组中待转换元素的始末位置。

  2. 代码如下:

  3. 上述算法的时间复杂度为O(n), 空间复杂度为O(1)。

+最后将整个a-1b-1逆置得到(a-1b-1)-1 = ba。

设Reverse函数执行将数组元素逆置的操作,对abcdefgh向左循环移动3(p=3)个位置的过程如下:

注: Reverse中, 两个参数分别表示数组中待转换元素的始末位置。

  • 代码如下:

  • 上述算法的时间复杂度为O(n), 空间复杂度为O(1)。

  • 8.寻找两正序数组中位数

    2011年真题

    一个长度为L(L≥1)的升序序列S,处在第 L/2个位置的数称为S的中位数。例如,若序列S1=(11,13,15,17,19),则S1的中位数是15,两个序列的中位数是含它们所有元素的升序序列的中位数。例如,若S2=(2,4,6,8,20),则S1和S2的中位数是11。现在有两个等长升序序列A和B,试设计一个在时间和空间两方面都尽可能高效的算法,找出两个序列A和B的中位数。要求:

    1. 给出算法的基本设计思想

    2. 根据设计思想,采用C、C++或Java语言描述算法,关键之处给出注释

    3. 说明你说设计算法的时间复杂度和空间复杂度

    解答:

    1. 分别求两个升序序列A、B的中位数,设为a和b。若a=b,则a或b即为所求中位数;否则,舍弃a、b中较小者所在序列之较小一半,同时舍弃较大者所在序列之较大一半,要求两次舍弃的元素个数相同。在保留的两个序列中,求新的中位数,重复上述过程,直到两个序列中均只含一个元素时为止,则较小者为所求的中位数。

    2. 代码如下:

    3. 时间复杂度为O(logn), 空间复杂度为O(1)。

    \ No newline at end of file diff --git "a/DS/2.LinearList/\344\273\243\347\240\201\351\242\230.md" "b/DS/2.LinearList/\344\273\243\347\240\201\351\242\230.md" index 930860d9136ce2e48d762047b21db8485ceed0c9..c93fe458481b6e0195a2a37744e90b87e70cdd36 100644 --- "a/DS/2.LinearList/\344\273\243\347\240\201\351\242\230.md" +++ "b/DS/2.LinearList/\344\273\243\347\240\201\351\242\230.md" @@ -48,7 +48,7 @@ ListNode *mergeTwoLists(ListNode *list1, ListNode *list2) { -# [2.求两链表交集](./2.LinearList/code_question/getTwoListsDifference.h) +# [2.求两链表交集](./code_question/getTwoListsDifference.h) 已知两个链表A和B分别表示两个集合,其元素递增排列。请设计一个算法,用于求出A与B的交集,并将结果存放在A链表中。 @@ -111,7 +111,7 @@ ListNode *mixTwoLists(ListNode *A, ListNode *B) { -# [3.分割链表](./2.LinearList/code_question/splitLinkList.h) +# [3.分割链表](./code_question/splitLinkList.h) 设计算法将一个带头结点的单链表A分解成两个具有相同结构的链表B和链表C,其中B表的节点为A表中值小于0的节点,而C表的节点为A表中值大于0的节点(链表A中的元素为非零整数,要求B、C表利用A表的节点) ```c++ @@ -148,7 +148,7 @@ vector splitListToParts(ListNode* head) { } ``` -# [4.查找链表最大值](./2.LinearList/code_question/findListMax.h) +# [4.查找链表最大值](./code_question/findListMax.h) 设计一个算法,通过一趟遍历确定长度为n的单链表中值最大的节点。 @@ -184,7 +184,7 @@ int findListMax_recursion(ListNode *list) { -# [5.反转链表](./2.LinearList/code_question/reverseList.h) +# [5.反转链表](./code_question/reverseList.h) 设计一个算法,将链表中所有节点的链接方向“原地”逆转,即要求仅利用原表的存储空间,换句话说,要求算法的空间复杂度为O(1) @@ -206,7 +206,7 @@ ListNode *reverseList(ListNode *head) { } ``` -# [6.求两链表差集](./2.LinearList/code_question/diffTwoLists.h) +# [6.求两链表差集](./code_question/diffTwoLists.h) 已知两个链表A和B分别表示两个集合,其元素递增排列。请设计一个算法,用于求出A与B的差集,并将结果存放在A链表中。 @@ -239,7 +239,7 @@ ListNode *diffTwoLists(ListNode *list1, ListNode *list2) { } ``` -# [7.数组左移](./2.LinearList/code_question/leftShift.h) +# [7.数组左移](./code_question/leftShift.h) ![2010年真题](https://badgen.net/static/真题/2010/green) @@ -280,4 +280,107 @@ ListNode *diffTwoLists(ListNode *list1, ListNode *list2) { } ``` -3. 上述算法的时间复杂度为O(n), 空间复杂度为O(1)。 \ No newline at end of file +3. 上述算法的时间复杂度为O(n), 空间复杂度为O(1)。 + +# [8.寻找两正序数组中位数](./code_question/M_Search.h) + +![2011年真题](https://badgen.net/static/真题/2011/green) + +一个长度为L(L≥1)的升序序列S,处在第 $\lceil L/2 \rceil$个位置的数称为S的中位数。例如,若序列S1=(11,13,15,17,19),则S1的中位数是15,两个序列的中位数是含它们所有元素的升序序列的中位数。例如,若S2=(2,4,6,8,20),则S1和S2的中位数是11。现在有两个等长升序序列A和B,试设计一个在时间和空间两方面都尽可能高效的算法,找出两个序列A和B的中位数。要求: + +1. 给出算法的基本设计思想 +2. 根据设计思想,采用C、C++或Java语言描述算法,关键之处给出注释 +3. 说明你说设计算法的时间复杂度和空间复杂度 + +解答: + +1. 分别求两个升序序列A、B的中位数,设为a和b。若a=b,则a或b即为所求中位数;否则,舍弃a、b中较小者所在序列之较小一半,同时舍弃较大者所在序列之较大一半,要求两次舍弃的元素个数相同。在保留的两个序列中,求新的中位数,重复上述过程,直到两个序列中均只含一个元素时为止,则较小者为所求的中位数。 +2. 代码如下: + ```c++ + int M_Search(int A[], int B[], int L) { + int s1, d1, m1, s2, d2, m2; + s1 = 0; d1 = L - 1; + s2 = 1; d2 = L - 1; + while (s1 != d1 || s2 != d2) { + m1 = (s1 + d1) / 2; + m2 = (s2 + d2) / 2; + if (A[m1] == B[m2]) return A[m1]; + if (A[m1] < B[m2]) { + s1 = m1 + (s1 + d1) % 2; // 需要考虑元素个数奇偶,保持两个子数组元素个数相等,(s1+d1)%2为1时,说明元素个数为奇数,此时s1=m1+1,否则就是s1=m1 + d2 = m2; + } else { + d1 = m1; + s2 = m2 + (s2 + d2) % 2; + } + } + return A[s1] < B[s2] ? A[s1] : B[s2]; // 三元表达式 + } + ``` + +3. 时间复杂度为O(logn), 空间复杂度为O(1)。 + +# [9.相交链表](./code_question/findSuffix.h) +![2012年真题](https://badgen.net/static/真题/2012/green) +[![leetcode](https://badgen.net/static/leetcode/160/f2a63f?icon=leetcode)](https://leetcode.cn/problems/intersection-of-two-linked-lists/submissions/477182932/) + +![题目](../../assets/images/2023-10-25_19.19.48.png) + +解答: +1. 1. 分别求出 str1 和 str2 所指的两个链表的长度m和n。 + 2. 将两个链表以表尾对齐:令指针 p、q 分别指向 str1 和 str2 的头结点,若m≥n,则使p指向链表中的第m-n+1个结点;若m<n,则使q指向链表中的第n一m+1个结点,即使指针p和q所指的结点到表尾的长度相等。 + 3. 反复将指针和q同步向后移动,并判断它们是否指向同一结点。若p和q指向同一结点,则该点即为所求的共同后缀的起始位置。 +2. ```c++ + struct ListNode { + int val; + ListNode *next; + }; // 不要忘了定义链表结点 + + int listlen(ListNode *head) { // 求链表长度 + int len = 0; + while (head->next != NULL) { + len++; + head = head->next; + } + return len; + } + + ListNode *findSuffix(ListNode *str1, ListNode *str2) { + int m, n; + ListNode *p, *q; + m = listlen(str1); // 求str1的长度.O(m) + n = listlen(str2); // 求str2的长度.O(n) + for (p = str1; m > n; m--) // 使p指向的链表与q指向的链表长度相等. + p = p->next; + for (q = str2; m < n; n--) // 使q指向的链表与p指向的链表长度相等. + q = q->next; + + while (p->next != NULL && p->next != q->next) { // 查找共同后缀的起始点 + p = p->next; + q = q->next; + } + return p->next; // 返回共同后缀的起始点 + } + ``` +3. 时间复杂度为O(m+n) + +另解: +1. 设A的长度为a+c,B的长度为b+c;其中c为A、B的公共部分长度。 + 拼接AB、BA:A+B=a+c+b+c B+A=b+c+a+c;由于a+c+b=b+c+a,因此二者必定在c的起始点处相遇 +2. ```c++ + struct ListNode { + int val; + ListNode *next; + }; // 不要忘了定义链表结点 + + ListNode *findSuffix(ListNode *str1, ListNode *str2){ + ListNode *p1=str1,*p2=str2; + + while (p1!=p2){ + p1=p1==nullptr?str2:p1->next; + p2=p2==nullptr?str1:p2->next; + } + return p1; + } + ``` +3. 时间复杂度为O(m+n) + diff --git "a/DS/3.Stack,Queue,Array/2.1\351\230\237\345\210\227\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265.html" "b/DS/3.Stack,Queue,Array/2.1\351\230\237\345\210\227\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265.html" index b74d4c4cadab245b7ca091731531be1f4b6f3970..663459b867842aadad93eac65e726d634643818d 100644 --- "a/DS/3.Stack,Queue,Array/2.1\351\230\237\345\210\227\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265.html" +++ "b/DS/3.Stack,Queue,Array/2.1\351\230\237\345\210\227\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ @media print { @page {margin: 0 0 0 0;} body.typora-export {padding-left: 0; padding-right: 0;} #write {padding:0;}} diff --git "a/DS/3.Stack,Queue,Array/2.4\345\217\214\347\253\257\351\230\237\345\210\227.html" "b/DS/3.Stack,Queue,Array/2.4\345\217\214\347\253\257\351\230\237\345\210\227.html" index c8b5a4ad392abdfa6b9f2bd75f98461a1851c350..d16e8c3c24b4a45ebbd9f1dea89944376e040752 100644 --- "a/DS/3.Stack,Queue,Array/2.4\345\217\214\347\253\257\351\230\237\345\210\227.html" +++ "b/DS/3.Stack,Queue,Array/2.4\345\217\214\347\253\257\351\230\237\345\210\227.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ @media print { @page {margin: 0 0 0 0;} body.typora-export {padding-left: 0; padding-right: 0;} #write {padding:0;}} diff --git "a/DS/3.Stack,Queue,Array/\344\273\243\347\240\201\351\242\230.html" "b/DS/3.Stack,Queue,Array/\344\273\243\347\240\201\351\242\230.html" index 1bd26148d9a3a6f09bcf01d330cdd675ee688554..1192d76b9001d3c72858a1f93a356058862b4ea3 100644 --- "a/DS/3.Stack,Queue,Array/\344\273\243\347\240\201\351\242\230.html" +++ "b/DS/3.Stack,Queue,Array/\344\273\243\347\240\201\351\242\230.html" @@ -821,30 +821,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ @@ -999,7 +999,7 @@ mjx-container[jax="SVG"] path[data-c], mjx-container[jax="SVG"] use[data-c] { 代码题
    -

    代码运行可以参考根目录下README.md中的程序调试和main.cpp

    题目标题不能直接跳转,需要把项目拉到本地用编译器打开后才能跳转,或者去仓库里找对应路径的代码文件

    代码头部添加using namespace std;可以使用string类型变量

    代码头部添加#include <stack>可以使用C++内置stack

    1.验证回文串

    回文是指正读、反读均相同的字符序列,如"abba"和"abdba"均是回文,但"good"不是回文。试设计算法判定给定的字符序列是否为回文。(提示:将一半字符入栈)

    这里实现的leetcode第125题 -翻转字符串判断或者双指针更方便,但毕竟是栈的题,还是按照课本的意思用栈实现

    2.计算后缀表达式

    从键盘上输入一个后缀表达式,试设计算法计算表达式的值。规定:逆波兰表达式长度不超过一行,输入以“$”作为结束,操作数之间用空格分开,操作符只可能有“+” “-” “*” “/”4种。例如:234 34 + 2*$

    思路:

    逆波兰表达式的计算就是先读到两个被操作数(其中一个数可能是前面计算出来的),然后读到运算符再对两个数进行运算。

    所以可以利用栈,每次读到数就放入栈中,读到运算符就从栈中取出两个元素(数字)进行对应的运算

     

    +

    代码运行可以参考根目录下README.md中的程序调试和main.cpp

    题目标题不能直接跳转,需要把项目拉到本地用编译器打开后才能跳转,或者去仓库里找对应路径的代码文件

    代码头部添加using namespace std;可以使用string类型变量

    代码头部添加#include <stack>可以使用C++内置stack

    1.验证回文串

    回文是指正读、反读均相同的字符序列,如"abba"和"abdba"均是回文,但"good"不是回文。试设计算法判定给定的字符序列是否为回文。(提示:将一半字符入栈)

    这里实现的leetcode第125题 +翻转字符串判断或者双指针更方便,但毕竟是栈的题,还是按照课本的意思用栈实现

    2.计算后缀表达式

    从键盘上输入一个后缀表达式,试设计算法计算表达式的值。规定:逆波兰表达式长度不超过一行,输入以“$”作为结束,操作数之间用空格分开,操作符只可能有“+” “-” “*” “/”4种。例如:234 34 + 2*$

    思路:

    逆波兰表达式的计算就是先读到两个被操作数(其中一个数可能是前面计算出来的),然后读到运算符再对两个数进行运算。

    所以可以利用栈,每次读到数就放入栈中,读到运算符就从栈中取出两个元素(数字)进行对应的运算

     

    \ No newline at end of file diff --git "a/DS/4.String/1.1\344\270\262\347\232\204\345\256\232\344\271\211.html" "b/DS/4.String/1.1\344\270\262\347\232\204\345\256\232\344\271\211.html" index 5339e62db17420aa380a66cfa588f452fb7377b8..aa117fa1fcb3bc09accc21566591a3a115c0db29 100644 --- "a/DS/4.String/1.1\344\270\262\347\232\204\345\256\232\344\271\211.html" +++ "b/DS/4.String/1.1\344\270\262\347\232\204\345\256\232\344\271\211.html" @@ -821,30 +821,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ @media print { @page {margin: 0 0 0 0;} body.typora-export {padding-left: 0; padding-right: 0;} #write {padding:0;}} diff --git "a/DS/4.String/2.1\346\250\241\345\274\217\345\214\271\351\205\215.html" "b/DS/4.String/2.1\346\250\241\345\274\217\345\214\271\351\205\215.html" index 8bf4deb4d3d19f76af0e9d1ed85fc3a2cabc2e9d..f80e6ac74ba0b1908d4225a273ac681ddcd8ec7c 100644 --- "a/DS/4.String/2.1\346\250\241\345\274\217\345\214\271\351\205\215.html" +++ "b/DS/4.String/2.1\346\250\241\345\274\217\345\214\271\351\205\215.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ @media print { @page {margin: 0 0 0 0;} body.typora-export {padding-left: 0; padding-right: 0;} #write {padding:0;}} diff --git "a/DS/4.String/2.2KMP\347\256\227\346\263\225.html" "b/DS/4.String/2.2KMP\347\256\227\346\263\225.html" index 5e5d44be4741f05b1922866adf02a9da2a501fee..2ee2cf353c10016e8a47df290a74f15ae191473e 100644 --- "a/DS/4.String/2.2KMP\347\256\227\346\263\225.html" +++ "b/DS/4.String/2.2KMP\347\256\227\346\263\225.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ @media print { @page {margin: 0 0 0 0;} body.typora-export {padding-left: 0; padding-right: 0;} #write {padding:0;}} diff --git "a/DS/5.Tree/2.2\344\272\214\345\217\211\346\240\221\347\232\204\345\255\230\345\202\250\347\273\223\346\236\204.html" "b/DS/5.Tree/2.2\344\272\214\345\217\211\346\240\221\347\232\204\345\255\230\345\202\250\347\273\223\346\236\204.html" index fe4e4e0043303f2162feed3220ea13bbee8a7c0e..a3ea6a408543ed7934bc053f2f624fad8e83e5a7 100644 --- "a/DS/5.Tree/2.2\344\272\214\345\217\211\346\240\221\347\232\204\345\255\230\345\202\250\347\273\223\346\236\204.html" +++ "b/DS/5.Tree/2.2\344\272\214\345\217\211\346\240\221\347\232\204\345\255\230\345\202\250\347\273\223\346\236\204.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ @media print { @page {margin: 0 0 0 0;} body.typora-export {padding-left: 0; padding-right: 0;} #write {padding:0;}} diff --git "a/DS/5.Tree/5.1\345\223\210\345\244\253\346\233\274\346\240\221.html" "b/DS/5.Tree/5.1\345\223\210\345\244\253\346\233\274\346\240\221.html" index 392cdf88ce217cffe41bcc9682faece56c0b3474..40890ea6fe607c35d2e08bcc28dfa8fbbbfdebf4 100644 --- "a/DS/5.Tree/5.1\345\223\210\345\244\253\346\233\274\346\240\221.html" +++ "b/DS/5.Tree/5.1\345\223\210\345\244\253\346\233\274\346\240\221.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ diff --git "a/DS/5.Tree/5.2\345\271\266\346\237\245\351\233\206.html" "b/DS/5.Tree/5.2\345\271\266\346\237\245\351\233\206.html" index fbd17180efa4639a7b54975c1abeb6932f8eec7a..36716f85d0b30ea5efdb8f84e0cd79295a8d2cc2 100644 --- "a/DS/5.Tree/5.2\345\271\266\346\237\245\351\233\206.html" +++ "b/DS/5.Tree/5.2\345\271\266\346\237\245\351\233\206.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ @media print { @page {margin: 0 0 0 0;} body.typora-export {padding-left: 0; padding-right: 0;} #write {padding:0;}} diff --git "a/DS/7.Serach/1\346\237\245\346\211\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265.html" "b/DS/7.Serach/1\346\237\245\346\211\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265.html" index 406c6716251e2764b8c7c044abe7f674495f6656..5112b92741e3b8e3d470bd71699c8f9c0dc8a3cc 100644 --- "a/DS/7.Serach/1\346\237\245\346\211\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265.html" +++ "b/DS/7.Serach/1\346\237\245\346\211\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ diff --git "a/DS/7.Serach/3.3\347\272\242\351\273\221\346\240\221.html" "b/DS/7.Serach/3.3\347\272\242\351\273\221\346\240\221.html" index a11faffea8702138e98f2d3fb8f04ce17328d1a0..874078a9493bcb68924ab33a8989fc6ce7d36e12 100644 --- "a/DS/7.Serach/3.3\347\272\242\351\273\221\346\240\221.html" +++ "b/DS/7.Serach/3.3\347\272\242\351\273\221\346\240\221.html" @@ -824,30 +824,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ diff --git "a/DS/7.Serach/4.3\346\225\243\345\210\227\350\241\250.html" "b/DS/7.Serach/4.3\346\225\243\345\210\227\350\241\250.html" index 0927abe11f57e66b1623bb2054ccf400117d3130..47e17f3a034d2d9c3dcc834279c5d013cb1fd54e 100644 --- "a/DS/7.Serach/4.3\346\225\243\345\210\227\350\241\250.html" +++ "b/DS/7.Serach/4.3\346\225\243\345\210\227\350\241\250.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ diff --git "a/DS/8.Sort/2\346\217\222\345\205\245\346\216\222\345\272\217.html" "b/DS/8.Sort/2\346\217\222\345\205\245\346\216\222\345\272\217.html" index 5444782e23ae8e60a9917b3ae1f123de3a6db5b7..e9b902a97670709b0f9c5390c911e70c4900fd6b 100644 --- "a/DS/8.Sort/2\346\217\222\345\205\245\346\216\222\345\272\217.html" +++ "b/DS/8.Sort/2\346\217\222\345\205\245\346\216\222\345\272\217.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ diff --git "a/DS/8.Sort/5\345\275\222\345\271\266\346\216\222\345\272\217\345\222\214\345\237\272\346\225\260\346\216\222\345\272\217.html" "b/DS/8.Sort/5\345\275\222\345\271\266\346\216\222\345\272\217\345\222\214\345\237\272\346\225\260\346\216\222\345\272\217.html" index 76aa347adf52bc738062f0a1f72272c871a8dcc6..1ad589c71816816ef2de9bc98b3d80739947fe1b 100644 --- "a/DS/8.Sort/5\345\275\222\345\271\266\346\216\222\345\272\217\345\222\214\345\237\272\346\225\260\346\216\222\345\272\217.html" +++ "b/DS/8.Sort/5\345\275\222\345\271\266\346\216\222\345\272\217\345\222\214\345\237\272\346\225\260\346\216\222\345\272\217.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ diff --git "a/DS/8.Sort/6\346\257\224\350\276\203\344\270\216\345\272\224\347\224\250.html" "b/DS/8.Sort/6\346\257\224\350\276\203\344\270\216\345\272\224\347\224\250.html" index 30d5fbed4168f3ca53402c1ff1480f2596fb9a5b..6aeb696818e0b7ff7531fcfba3d314ce94a94a2e 100644 --- "a/DS/8.Sort/6\346\257\224\350\276\203\344\270\216\345\272\224\347\224\250.html" +++ "b/DS/8.Sort/6\346\257\224\350\276\203\344\270\216\345\272\224\347\224\250.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ @media print { @page {margin: 0 0 0 0;} body.typora-export {padding-left: 0; padding-right: 0;} #write {padding:0;}} diff --git "a/DS/8.Sort/7\345\244\226\351\203\250\346\216\222\345\272\217.html" "b/DS/8.Sort/7\345\244\226\351\203\250\346\216\222\345\272\217.html" index 4755c2924bb95c632cfc85635423e5ae1458e038..f973f917d3d0597425127bf98c79da34b7657e38 100644 --- "a/DS/8.Sort/7\345\244\226\351\203\250\346\216\222\345\272\217.html" +++ "b/DS/8.Sort/7\345\244\226\351\203\250\346\216\222\345\272\217.html" @@ -740,30 +740,30 @@ footer { .sidebar-content-content { font-size: 0.9rem; -}@import ""; - -:root { - --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - --title-font: var(--base-font); - --monospace: "Ubuntu Mono", Courier, Monospace !important; -} - -/* Cesno style start */ - -.cm-s-inner .cm-variable {color: #f39800;} - -.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} - -.cm-s-inner .cm-number {color: #e95295;} - -.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} - -.cm-s-inner .cm-def {color: #0094c8;} - -.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} - -/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ - +}@import ""; + +:root { + --base-font: Consolas , "Ubuntu Mono", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + --title-font: var(--base-font); + --monospace: "Ubuntu Mono", Courier, Monospace !important; +} + +/* Cesno style start */ + +.cm-s-inner .cm-variable {color: #f39800;} + +.cm-s-inner .cm-variable-3 {color: #9ed44c; font-weight: bold;} + +.cm-s-inner .cm-number {color: #e95295;} + +.cm-s-inner .cm-keyword {color: #bc64a4; font-weight: bold;} + +.cm-s-inner .cm-def {color: #0094c8;} + +.cm-s-inner .cm-operator {color: #a59aca; font-weight: bold;} + +/* .cm-s-inner .cm-atom {color: #c5c56a; font-weight: bold;} */ + /* Cesno style end */ diff --git a/DS/CMakeLists.txt b/DS/CMakeLists.txt index 7cf63a3bba0619b85aec8722587f6df3a9e364e8..971a9d7c7884fd759b65f0be203b1b26dccc63b7 100644 --- a/DS/CMakeLists.txt +++ b/DS/CMakeLists.txt @@ -5,4 +5,6 @@ set(CMAKE_CXX_STANDARD 14) add_executable(DataStructure main.cpp 2.LinearList/2.1顺序表定义.h 2.LinearList/2.2顺序表的实现_静态分配.h 2.LinearList/2.2顺序表的实现_静态分配.h 2.LinearList/2.2顺序表的实现_动态分配.h 2.LinearList/3.2单链表的实现.h 2.LinearList/3.3双链表.h 2.LinearList/3.4循环链表.h 2.LinearList/3.4循环双链表.h 2.LinearList/3.5静态链表.h 3.Stack,Queue,Array/1.1栈的基本概念.h 3.Stack,Queue,Array/1.2顺序栈.h 3.Stack,Queue,Array/1.3链栈.h 3.Stack,Queue,Array/2.1队列的基本概念.h 3.Stack,Queue,Array/2.2顺序队列.h 3.Stack,Queue,Array/2.3链队列.h 3.Stack,Queue,Array/3.1栈匹配括号.h 4.String/1串的定义.h 4.String/2.1串的模式匹配.h 4.String/2.2KMP算法.h 5.Tree/2.2顺序树.h 5.Tree/2.2链式树.h 5.Tree/3.1二叉树的遍历.h 5.Tree/3.2线索二叉树.h 5.Tree/5.5并查集.h 6.Graph/2.1邻接矩阵.h 6.Graph/2.2邻接表.h 6.Graph/2.3十字链表.h 6.Graph/3.1广度优先搜索.h 6.Graph/3.2深度优先搜索.h "6.Graph/3.1广度优先搜索(邻接表).h" "6.Graph/2.3深度优先搜索(邻接表).h" "6.Graph/4.2BFS(最短路径).h" 6.Graph/4.2Dijkstra.h 6.Graph/4.2Floyd.h 7.Serach/顺序查找.h 7.Serach/二分查找.h 7.Serach/二叉排序树.h 7.Serach/AVL树.h 7.Serach/B树.h 7.Serach/B+树.h 8.Sort/折半排序.h 8.Sort/插入排序.h 8.Sort/冒泡排序.h 8.Sort/快速排序.h 8.Sort/选择排序.h 8.Sort/堆排序.h 8.Sort/utils.h 8.Sort/归并排序.h 2.LinearList/code_question/LinkList.h 2.LinearList/code_question/splitLinkList.h 2.LinearList/code_question/mergeTwoLists.h 2.LinearList/code_question/mixTwoLists.h 2.LinearList/code_question/findListMax.h 2.LinearList/code_question/reverseList.h 3.Stack,Queue,Array/code_question/isPalindrome.h 3.Stack,Queue,Array/code_question/evalRPN.h 2.LinearList/code_question/diffTwoLists.h - 2.LinearList/code_question/leftShift.h) \ No newline at end of file + 2.LinearList/code_question/leftShift.h + 2.LinearList/code_question/M_Search.h + 2.LinearList/code_question/findSuffix.h) \ No newline at end of file diff --git a/DS/main.cpp b/DS/main.cpp index 1e51551362b222e40909d75ca19c91dc88b00230..a379b94a0d5e3eee9df4e074b3f7016e251d3d1c 100644 --- a/DS/main.cpp +++ b/DS/main.cpp @@ -3,8 +3,9 @@ * * DataStructure后面只留下要运行的文件名就行 */ -#include "3.Stack,Queue,Array/2.2循环队列.h" +#include "2.LinearList/code_question/findSuffix.h" -int main(){ +int main() { TestModule(); + return 1; } \ No newline at end of file diff --git a/assets/images/2023-10-25_19.19.48.png b/assets/images/2023-10-25_19.19.48.png new file mode 100644 index 0000000000000000000000000000000000000000..c61043fe6f2fc78c933a1b4d6a0909469a9ee050 Binary files /dev/null and b/assets/images/2023-10-25_19.19.48.png differ