上一页 1 2 3 4 5 6 7 ··· 69 下一页

2025年11月29日

反转链表

摘要: 题目描述:输入一个链表,反转链表后,输出链表的所有元素。 思路:遍历链表时通过头插法来插入链表结点。 步骤: 1 如果链表为空,返回null。 2 当前首结点设为尾结点。 3 遍历链表,通过头插法把当前链表结点插入到当前首结点的前面。 4 返回反转链表后的首结点。 时间复杂度:O(n)。 Java代 阅读全文

posted @ 2025-11-29 15:04 王景迁 阅读(6) 评论(0) 推荐(0)

二叉树的深度

摘要: 题目描述:输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。 思路:通过广度优先遍历(BFS)来获取二叉树的深度。 步骤: 1 如果根结点为空,则返回0。 2 创建实现了Queue接口的LinkedList对象。 3 通过队列来执 阅读全文

posted @ 2025-11-29 15:03 王景迁 阅读(5) 评论(0) 推荐(0)

二叉树的镜像

摘要: 题目描述:操作给定的二叉树,将其变换为源二叉树的镜像。 思路:通过BFS来遍历每个结点,交换当前结点的左右孩子结点即交换左右子树。 步骤: 1 如果根结点为空或者只有一个结点,则结束。 2 创建实现了Queue接口的LinkedList对象。 3 根结点入队列。 4 通过BFS来遍历每个结点,交换当 阅读全文

posted @ 2025-11-29 15:03 王景迁 阅读(3) 评论(0) 推荐(0)

5-18 Hashing - Hard Version (30分)

摘要: #include <iostream> #include <vector> #include <queue> using namespace std; struct node { int key, index; bool operator < (const node &nod) const { re 阅读全文

posted @ 2025-11-29 15:00 王景迁 阅读(3) 评论(0) 推荐(0)

5-14 电话聊天狂人 (25分)

摘要: #include <iostream> #include <map> using namespace std; int main() { int n; scanf("%d", &n); int i; long long num; map<long long, int> m; for(i = 1; i 阅读全文

posted @ 2025-11-29 15:00 王景迁 阅读(2) 评论(0) 推荐(0)

5-11 关键活动 (30分)

摘要: #include <iostream> #include <vector> #include <queue> using namespace std; struct node { int next, time; }; int degree[2][110], t[2][110], maxtime; v 阅读全文

posted @ 2025-11-29 14:59 王景迁 阅读(2) 评论(0) 推荐(0)

5-10 公路村村通 (30分)

摘要: #include <iostream> #include <algorithm> using namespace std; struct edge { int a, b, cost; }e[3010]; int sum[1010], tree[1010], res; int cmp(edge e1, 阅读全文

posted @ 2025-11-29 14:59 王景迁 阅读(1) 评论(0) 推荐(0)

5-10 Saving James Bond - Easy Version (25分)

摘要: #include <iostream> #include <math.h> using namespace std; struct node { int x, y, flag; }vis[110]; int flag, d, n; double getdis(int index0, int inde 阅读全文

posted @ 2025-11-29 14:59 王景迁 阅读(2) 评论(0) 推荐(0)

5-9 Huffman Codes (30分)

摘要: #include <iostream> #include <queue> #include <vector> #include <string.h> using namespace std; int judge(char a[], char b[], int alen, int blen) { in 阅读全文

posted @ 2025-11-29 14:58 王景迁 阅读(3) 评论(0) 推荐(0)

5-8 哈利·波特的考试 (25分)

摘要: #include <iostream> #include <vector> #include <string.h> using namespace std; struct node { int next, dis; }; int tree[110], sum[110], flag[110]; int 阅读全文

posted @ 2025-11-29 14:58 王景迁 阅读(4) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 ··· 69 下一页

导航