GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add · hfl15/algorithm@6a7ba40

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • sword_offer
    • README.md
    • src
      • 001.cpp
      • 002.cpp
      • 003.cpp
      • 004.cpp
      • 005.cpp
      • 006.cpp
      • 007.cpp
      • 008.cpp
      • 009.cpp
      • 010.cpp
      • 011.cpp
      • 012.cpp
      • 013.cpp
      • 014.cpp
      • 015.cpp
      • 016.cpp
      • 017.cpp
      • 018.cpp
      • 019.cpp
      • 020.cpp
      • 021.cpp
      • 022.cpp
      • 023.cpp
      • 024.cpp
      • 025.cpp
      • 026.cpp
      • 027.cpp
      • 028.cpp
      • 029.cpp
      • 030.cpp
      • 031.cpp
      • 032.cpp
      • 033.cpp
      • 034.cpp
      • 035.cpp
      • 036.cpp
      • 037.cpp
      • 038.cpp
      • 039.cpp
      • 040.cpp
      • 041.cpp
      • 042.cpp
      • 043.cpp
      • 044.cpp
      • 045.cpp
      • 046.cpp
      • 047.cpp
      • 048.cpp
      • 049.cpp
      • 050.cpp
      • 051.cpp
      • 052.cpp
      • 053.cpp
      • 054.cpp
      • 055.cpp
      • 056.cpp
      • 057.cpp
      • 058.cpp
      • 059.cpp
      • 060.cpp
      • 061.cpp
      • 062.cpp
      • 063.cpp
      • 064.cpp
      • in.txt
      • test

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎sword_offer/README.md‎

Copy file name to clipboard
+126Lines changed: 126 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
## 面试思路:
2+
3+
- [x] [001-二叉树的镜像](src/001.cpp)
4+
5+
## 链表:
6+
7+
- [x] [002-删除链表中重复的结点](src/002.cpp)
8+
- [x] [003-链表中环的入口结点](src/003.cpp)
9+
- [x] [004-从尾到头打印链表](src/004.cpp)
10+
11+
## 递归和循环:
12+
13+
- [x] [005-跳台阶](src/005.cpp)
14+
- [x] [006-变态跳台阶](src/006.cpp)
15+
- [x] [007-斐波那契数列](src/007.cpp)
16+
- [x] [008-矩形覆盖](src/008.cpp)
17+
18+
## 综合:
19+
20+
- [x] [009-把字符串转换成整数](src/009.cpp)
21+
22+
## 知识迁移能力:
23+
24+
- [x] [010-和为S的连续正数序列](src/010.cpp)
25+
- [x] [011-平衡二叉树](src/011.cpp)
26+
- [x] [012-和为S的两个数字](src/012.cpp)
27+
- [x] [013-二叉树的深度](src/013.cpp)
28+
- [x] [014-翻转单词顺序列](src/014.cpp)
29+
- [x] [015-数字在排序数组中出现的次数](src/015.cpp)
30+
- [x] [016-数组中只出现一次的数字](src/016.cpp)
31+
- [x] [017-左旋转字符串](src/017.cpp)
32+
- [x] [018-顺时针打印矩阵](src/018.cpp)
33+
34+
## 树:
35+
36+
- [x] [019-二叉树的下一个结点](src/019.cpp)
37+
- [x] [020-序列化二叉树](src/020.cpp)
38+
- [x] [021-按之字形顺序打印二叉树](src/021.cpp)
39+
- [x] [022-把二叉树打印成多行](src/022.cpp)
40+
- [x] [023-对称的二叉树](src/023.cpp)
41+
- [x] [024-二叉搜索树的第k个结点](src/024.cpp)
42+
- [x] [025-数据流中的中位数](src/025.cpp)
43+
- [x] [026-重建二叉树](src/026.cpp)
44+
45+
## 栈和队列:
46+
47+
- [x] [027-滑动窗口的最大值](src/027.cpp)
48+
- [x] [028-用两个栈实现队列](src/028.cpp)
49+
50+
51+
## 查找和排序:
52+
53+
- [x] [029-旋转数组的最小数字](src/029.cpp)
54+
55+
## 时间空间效率的平衡:
56+
57+
- [x] [030-丑数](src/030.cpp)
58+
- [x] [031-数组中的逆序对](src/031.cpp)
59+
- [x] [032-两个链表的第一个公共结点](src/032.cpp)
60+
- [x] [033-第一个只出现一次的字符位置](src/033.cpp)
61+
62+
## 时间效率:
63+
64+
- [x] [034-最小的K个数](src/034.cpp)
65+
- [x] [035-连续子数组的最大和](src/035.cpp)
66+
- [x] [036-把数组排成最小的数](src/036.cpp)
67+
- [x] [037-整数中1出现的次数(从1到n整数中1出现的次数)](src/037.cpp)
68+
- [x] [038-数组中出现次数超过一半的数字](src/038.cpp)
69+
70+
## 数组:
71+
72+
- [x] [039-构建乘积数组](src/039.cpp)
73+
- [x] [040-数组中重复的数字](src/040.cpp)
74+
- [x] [041-二维数组中的查找](src/041.cpp)
75+
76+
## 抽象建模能力:
77+
78+
- [x] [042-扑克牌顺子](src/042.cpp)
79+
- [x] [043-孩子们的游戏(圆圈中最后剩下的数)](src/043.cpp)
80+
81+
## 字符串:
82+
83+
- [x] [044-字符流中第一个不重复的字符](src/044.cpp)
84+
- [x] [045-表示数值的字符串](src/045.cpp)
85+
- [x] [046-正则表达式匹配](src/046.cpp)
86+
- [x] [047-替换空格](src/047.cpp)
87+
88+
## 回溯法:
89+
90+
- [x] [048-矩阵中的路径](src/048.cpp)
91+
- [x] [049-机器人的运动范围](src/049.cpp)
92+
93+
## 发散思维能力:
94+
95+
- [x] [050-不用加减乘除做加法](src/050.cpp)
96+
- [ ] 求1+2+3+...+n
97+
98+
## 分解让复杂问题简单:
99+
100+
- [x] [051-二叉搜索树与双向链表](src/051.cpp)
101+
- [x] [052-复杂链表的复制](src/052.cpp)
102+
- [x] [053-字符串的排列](src/053.cpp)
103+
104+
## 位运算:
105+
106+
- [x] [054-二进制中1的个数](src/054.cpp)
107+
108+
## 代码的鲁棒性:
109+
110+
- [x] [055-树的子结构](src/055.cpp)
111+
- [x] [056-合并两个排序的链表](src/056.cpp)
112+
- [x] [057-链表中倒数第k个结点](src/057.cpp)
113+
- [x] [058-调整数组顺序使奇数位于偶数前面](src/058.cpp)
114+
115+
## 代码的完整性:
116+
117+
- [x] [059-数值的整数次方](src/059.cpp)
118+
119+
## 举例让抽象具体化:
120+
121+
- [x] [060-栈的压入、弹出序列](src/060.cpp)
122+
- [x] [061-二叉搜索树的后序遍历序列](src/061.cpp)
123+
- [x] [062-从上往下打印二叉树](src/062.cpp)
124+
- [x] [063-二叉树中和为某一值的路径](src/063.cpp)
125+
- [x] [064-包含min函数的栈](src/064.cpp)
126+
Collapse file

‎sword_offer/src/001.cpp‎

Copy file name to clipboard
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
[二叉树的镜像]
3+
4+
操作给定的二叉树,将其变换为源二叉树的镜像。
5+
二叉树的镜像定义:
6+
源二叉树
7+
8
8+
| |
9+
6 10
10+
| | | |
11+
5 7 9 11
12+
镜像二叉树
13+
8
14+
| |
15+
10 6
16+
| | | |
17+
11 9 7 5
18+
*/
19+
#include <iostream>
20+
#include <algorithm>
21+
22+
using namespace std;
23+
24+
struct TreeNode{
25+
int val;
26+
TreeNode *left;
27+
TreeNode *right;
28+
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
29+
};
30+
31+
class Solution{
32+
public:
33+
void Mirror(TreeNode *pRoot){
34+
if(pRoot == NULL)
35+
return;
36+
37+
swap(pRoot->left, pRoot->right);
38+
Mirror(pRoot->left);
39+
Mirror(pRoot->right);
40+
}
41+
};
42+
43+
int main()
44+
{
45+
return 0;
46+
}
Collapse file

‎sword_offer/src/002.cpp‎

Copy file name to clipboard
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
[删除链表中重复的结点]
3+
4+
在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。
5+
例如,链表1->2->3->3->4->4->5 处理后为 1->2->5
6+
*/
7+
8+
9+
#include <iostream>
10+
#include <vector>
11+
#include <algorithm>
12+
13+
using namespace std;
14+
15+
struct ListNode{
16+
int val;
17+
ListNode *next;
18+
ListNode(int x) : val(x), next(NULL) {}
19+
};
20+
21+
class Solution{
22+
public:
23+
ListNode* deleteDuplication(ListNode* pHead){
24+
if(pHead == NULL)
25+
return NULL;
26+
27+
ListNode *pPrev = NULL;
28+
ListNode *pCur = pHead;
29+
while(pCur && pCur->next){
30+
ListNode *pNext = pCur->next;
31+
if(pNext->val != pCur->val){
32+
pPrev = pCur;
33+
pCur = pNext;
34+
}else{
35+
// find all duplicate
36+
while(pNext && pNext->val == pCur->val)
37+
pNext = pNext->next;
38+
if(pPrev == NULL){
39+
pHead = pNext;
40+
}else{
41+
pPrev->next = pNext;
42+
}
43+
44+
pCur = pNext;
45+
}
46+
}
47+
48+
return pHead;
49+
}
50+
};
51+
52+
int main()
53+
{
54+
return 0;
55+
}
Collapse file

‎sword_offer/src/003.cpp‎

Copy file name to clipboard
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
[链表中环的入口结点]
3+
一个链表中包含环,请找出该链表的环的入口结点。
4+
*/
5+
6+
#include <iostream>
7+
#include <vector>
8+
#include <algorithm>
9+
10+
using namespace std;
11+
12+
struct ListNode{
13+
int val;
14+
ListNode *next;
15+
ListNode(int x): val(x), next(NULL) {}
16+
};
17+
18+
class Solution{
19+
public:
20+
ListNode* EntryNodeOfLoop(ListNode* pHead){
21+
if(pHead == NULL)
22+
return NULL;
23+
24+
// count the number notes in loop
25+
ListNode* pSlow = pHead;
26+
ListNode* pFast = pHead->next; // pFast will purse the pSlow
27+
while(pFast && pFast->next){
28+
if(pSlow == pFast)
29+
break;
30+
pSlow = pSlow->next;
31+
pFast = pFast->next->next;
32+
}
33+
if(pFast == NULL || pFast->next == NULL) // no loop
34+
return NULL;
35+
36+
int k = 1;
37+
pSlow = pSlow->next;
38+
while(pSlow != pFast){
39+
pSlow = pSlow->next;
40+
k++;
41+
}
42+
43+
pSlow = pHead;
44+
pFast = pHead;
45+
for(int i=2; i<=k+1; i++){
46+
pFast = pFast->next;
47+
}
48+
49+
while(pSlow != pFast){
50+
pSlow = pSlow->next;
51+
pFast = pFast->next;
52+
}
53+
54+
return pFast;
55+
}
56+
};
57+
58+
int main()
59+
{
60+
return 0;
61+
}
Collapse file

‎sword_offer/src/004.cpp‎

Copy file name to clipboard
+57Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
[从尾到头打印链表]
3+
输入一个链表,从尾到头打印链表每个节点的值。
4+
*/
5+
6+
#include <iostream>
7+
#include <algorithm>
8+
#include <vector>
9+
#include <stack>
10+
11+
using namespace std;
12+
13+
struct ListNode{
14+
int val;
15+
ListNode* next;
16+
ListNode(int x) : val(x), next(NULL) {}
17+
};
18+
19+
class Solution{
20+
public:
21+
vector<int> printListFromTailToHead(ListNode* head){
22+
// vector<int> ans;
23+
// printListFromTailToHeadRecursive(head, ans);
24+
// return ans;
25+
26+
return printListFromTailToHeadIterate(head);
27+
}
28+
29+
vector<int> printListFromTailToHeadIterate(ListNode* head){
30+
vector<int> ans;
31+
stack<int> sNotes;
32+
ListNode* p = head;
33+
while(p){
34+
sNotes.push(p->val);
35+
p = p->next;
36+
}
37+
38+
while(!sNotes.empty()){
39+
ans.push_back(sNotes.top());
40+
sNotes.pop();
41+
}
42+
43+
return ans;
44+
}
45+
46+
void printListFromTailToHeadRecursive(ListNode* head, vector<int>& ans){
47+
if(head == NULL)
48+
return;
49+
printListFromTailToHeadRecursive(head->next, ans);
50+
ans.push_back(head->val);
51+
}
52+
};
53+
54+
int main()
55+
{
56+
return 0;
57+
}
Collapse file

‎sword_offer/src/005.cpp‎

Copy file name to clipboard
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
[跳台阶]
3+
4+
一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
5+
*/
6+
7+
8+
#include <iostream>
9+
#include <vector>
10+
#include <algorithm>
11+
12+
using namespace std;
13+
14+
class Solution{
15+
public:
16+
int jumpFloor(int number){
17+
if(number == 1)
18+
return 1;
19+
if(number == 2)
20+
return 2;
21+
22+
// f[n] = f[n-1] + f[n-2]
23+
int f1 = 1;
24+
int f2 = 2;
25+
for(int i=3; i<=number; i++){
26+
int temp = f1 + f2;
27+
f1 = f2;
28+
f2 = temp;
29+
}
30+
31+
return f2;
32+
}
33+
};
34+
35+
int main()
36+
{
37+
return 0;
38+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.