From 27f8d76eafc05f297238acbc3e2764c196460e97 Mon Sep 17 00:00:00 2001 From: 1AoB <2453468739@qq.com> Date: Mon, 22 Apr 2024 17:53:18 +0800 Subject: [PATCH] c++ --- .../2024-04-20七大排序算法/index.zh-cn.md | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/exampleSite/content/post/2024-04-20七大排序算法/index.zh-cn.md b/exampleSite/content/post/2024-04-20七大排序算法/index.zh-cn.md index 90fbc37..985b445 100644 --- a/exampleSite/content/post/2024-04-20七大排序算法/index.zh-cn.md +++ b/exampleSite/content/post/2024-04-20七大排序算法/index.zh-cn.md @@ -254,4 +254,50 @@ vector MySort(vector& arr) { -这个我也只是了解过基本的原理,并没有实际使用过. \ No newline at end of file +这个我也只是了解过基本的原理,并没有实际使用过. + +--- + +## 反转链表 + +[206. 反转链表](https://leetcode.cn/problems/reverse-linked-list/) + +```cpp + +``` + + + +## 层序遍历 + +[102. 二叉树的层序遍历](https://leetcode.cn/problems/binary-tree-level-order-traversal/) + +```cpp +class Solution { +public: + vector> levelOrder(TreeNode* root) { + vector>res; + if(!root)return res; + queueq;//中间变量 + q.push(root); + while(!q.empty()) + { + vector level;//每一层的结点(要放到答案res里面的) + int len = q.size();//这一层的节点个数 + while(len --) + { + auto t = q.front(); + q.pop(); + level.push_back(t->val); + + //未下一层做准备 + if(t->left)q.push(t->left); + if(t->right)q.push(t->right); + } + res.push_back(level); + } + return res; + } +}; +``` +