摘要: 考察二叉树的遍历。判断前序遍历,与新增的前->右->左遍历结果是否一致。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义二叉树 struct TreeNode{ int val; struct Tree 阅读全文
posted @ 2020-07-25 21:53 程序员曾奈斯 阅读(149) 评论(0) 推荐(0)
摘要: 考察二叉树的遍历。镜像对称,本解法使用的是前序遍历。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义二叉树 struct TreeNode{ int val; struct TreeNode* left 阅读全文
posted @ 2020-07-25 21:05 程序员曾奈斯 阅读(141) 评论(0) 推荐(0)
摘要: 考察二叉树的遍历。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义二叉树 struct TreeNode{ int val; struct TreeNode* left; struct TreeNode 阅读全文
posted @ 2020-07-25 20:22 程序员曾奈斯 阅读(147) 评论(0) 推荐(0)
摘要: 考察链表的操作,合并两个有序链表,合并后的链表仍是有序的。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义链表 struct ListNode{ int val; struct ListNode* ne 阅读全文
posted @ 2020-07-25 19:37 程序员曾奈斯 阅读(106) 评论(0) 推荐(0)
摘要: 考察链表的操作,将单向链表反转,返回头节点。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义链表 struct ListNode{ int val; struct ListNode* next; Lis 阅读全文
posted @ 2020-07-25 19:20 程序员曾奈斯 阅读(111) 评论(0) 推荐(0)
摘要: 考察链表的操作,找到单向链表中环的入口节点 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义链表 struct ListNode{ int val; struct ListNode* next; List 阅读全文
posted @ 2020-07-25 18:39 程序员曾奈斯 阅读(126) 评论(0) 推荐(0)
摘要: 考察链表的操作,注意使用一次遍历。相关题目:求链表的中间节点。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义链表 struct ListNode{ int val; struct ListNode* 阅读全文
posted @ 2020-07-25 16:23 程序员曾奈斯 阅读(99) 评论(0) 推荐(0)