Compare commits

..

11 Commits

Author SHA1 Message Date
Chuyaoyuan dd96d763b6 Update README.md
🚀 Deploy website on push / 🎉 Deploy (push) Has been cancelled
2026-01-23 11:59:30 +08:00
Chuyaoyuan 64582c4a57 支持数学公式和docs页面修改
支持数学公式和docs页面修改
2021-05-13 00:16:22 +08:00
Chuyaoyuan afd35da17f Merge pull request #11 from Chuyaoyuan/develop-zbh
Merge pull request #10 from Chuyaoyuan/main
2021-05-11 09:50:31 -05:00
Chuyaoyuan a2567c1865 Merge pull request #10 from Chuyaoyuan/main
Merge pull request #9 from Chuyaoyuan/develop-zbh
2021-05-11 09:49:37 -05:00
Chuyaoyuan 8427bc93ac Merge pull request #9 from Chuyaoyuan/develop-zbh
Develop zbh
2021-05-11 09:48:43 -05:00
Chuyaoyuan a29e19b4d5 Merge pull request #8 from Chuyaoyuan/main
合并
2021-05-11 09:48:03 -05:00
BohouZhang 81059620ee 【feat】:新增文章《二叉树的遍历》,解决leetcode的94,144,145题 2021-05-09 16:42:57 +08:00
Chuyaoyuan 357c4d37f2 Merge pull request #7 from Chuyaoyuan/develop-zbh
Develop zbh
2021-05-03 11:13:02 -05:00
Chuyaoyuan c22c77d3b7 【feat】:中文改英文目录 2021-05-04 00:11:24 +08:00
Chuyaoyuan 1774f5e892 【feat】:剑指offer目录添加,md中jsx语法调整 2021-05-04 00:04:31 +08:00
Chuyaoyuan a03f416199 Merge pull request #6 from Chuyaoyuan/develop-zbh
Merge pull request #5 from Chuyaoyuan/main
2021-04-28 21:05:11 -05:00
29 changed files with 254 additions and 28 deletions
Vendored
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -18,7 +18,7 @@
# 在线体验
- [[首页地址]](http://docs.yaoyuan.io/)
- [[首页地址]](http://docs.cyy.im/)
# 部署
## [一]、开发环境配置
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -1,4 +1,4 @@
{
"label": "1 - 100",
"position": 2
"position": 3
}
+1 -1
View File
@@ -1,4 +1,4 @@
{
"label": "100 - 200",
"position": 3
"position": 4
}
Binary file not shown.
@@ -1,4 +1,4 @@
# 队列\_剑指Offer59题\_队列的最大值问题
# 队列的最大值问题
## 题目描述如下:
@@ -64,7 +64,7 @@ class MaxQueue {
本着先实现,后优化的原则,最容易想到的解决方案是这样的:
<span style="color:blue">用一个队列保存所有的数据,这样保证了push和pop操作是正常执行的。然后将这个队列从大到小排列到另一个数据结构中,这样执行max_value方法时输出数组第一项即可。删除队列中数据的时候,用来排序的数据结构中的对应数据也应该删掉。</span>
<span style={{color:'blue'}}>用一个队列保存所有的数据,这样保证了push和pop操作是正常执行的。然后将这个队列从大到小排列到另一个数据结构中,这样执行max_value方法时输出数组第一项即可。删除队列中数据的时候,用来排序的数据结构中的对应数据也应该删掉。</span>
于是乎很容易写出这样的代码:
@@ -112,7 +112,7 @@ class MaxQueue {
}
~~~
接下来考虑着三个TODO项如何去解决。首先要确定的是<span style="color:red">用什么数据结构保存sortedDatas</span>。
接下来考虑着三个TODO项如何去解决。首先要确定的是<span style={{color:'red'}}>用什么数据结构保存sortedDatas</span>。
| 数据结构 | 优劣分析 | 结论 |
| -------- | ------------------------------------------------------------ | ---------- |
@@ -122,13 +122,13 @@ class MaxQueue {
| 队列 | 单调递减的队列。遇到的问题和栈一致。 | |
| 树 | 最大二叉树能实现,但是树在内存中也是以数组的形式保存的,问题和数组一致。 | :no_entry: |
所以说,要么用栈,要么用数组来保存sortedDatas中的数据。所以决定采用双端队列来处理sortedDatas,因为**双端队列能同时满足栈、队列的所有操作**。下一个问题便是……<span style="color:red">如何给这个双端队列进行排序</span>。
所以说,要么用栈,要么用数组来保存sortedDatas中的数据。所以决定采用双端队列来处理sortedDatas,因为**双端队列能同时满足栈、队列的所有操作**。下一个问题便是……<span style={{color:'red'}}>如何给这个双端队列进行排序</span>。
堆排序、快速排序的时间复杂度是O(n lg n);其他的线性排序算法时间复杂度是O(n)。这些都不太满足题目的要求。所以这里我想到了一种可能性:**有些数是不是没有参与排序**?如果队列中有n个数字,参与排序的数字小于n,那么排序的时间复杂度会更小的。那么,**什么样的数字可能不用参与排序呢**?max\_value方法要输出的是最大的数,所以最大的数字是一定参与排序的,即比较小的数字可以不用参与排序——我只管最大的数,其他的数字顺序对与否甚至数据的有无,都不会影响到最后的结果。
所以进一步的解决方案是这样的:
<span style="color:red">每次有新的数据插入的时候,将sortedDatas中的数据从后往前跟入参比较,如果小于入参,就直接舍弃掉,直到遇到比入参大的数字时再将入参存入队列中。</span>
<span style={{color:'red'}}>每次有新的数据插入的时候,将sortedDatas中的数据从后往前跟入参比较,如果小于入参,就直接舍弃掉,直到遇到比入参大的数字时再将入参存入队列中。</span>
这样的好处显而易见:小于入参的数字不会影响到最大值的输出。另一方面,队列中的数据来得比现在这个入参早,所以小于入参的数字会比这个入参更早的被删除掉。即,小于入参的数字永远不可能作为最大值背输出出来。
Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

@@ -0,0 +1,124 @@
# 二叉树的遍历
二叉树本质上可以理解为链表的一种扩展。对于单向链表而言,每个节点都有一个指针指向下一个节点。如果将这个指针增加为两个,即每个节点都有两个指针指向两个字节点,这个链表就变成了一颗二叉树。为了方便起见,我们可以将这两个指针分别命名为left和right,以表示左子节点和右子节点。
我们可以通过一个简单的递归算法来输出二叉树中的所有元素。常见的遍历方法包括**中序遍历(LDR)**、**先序遍历(DLR)**和**后序遍历(LRD)**。
> 先序遍历指的是输出的子树根的关键字位于其左子树的关键字和右子树的关键字值之间。类似地,先序遍历中输出的根的关键字在其左右子树的关键字之前;后序遍历输出的根的关进子在其左右子树的关键字值之后。[^ 1 ]
![image-20210509150025832](二叉树的遍历.assets/image-20210509150025832.png)
以上述二叉树为例,不同的遍历方式得到的序列分别是:
**前序遍历:**15 -> 9 -> 3 -> 1 -> 8 -> 12 -> 23 -> 17 -> 28
**中序遍历:**1 -> 3 -> 8 -> 9 -> 12 -> 15 -> 17 -> 23 -> 28
**后序遍历:**1 -> 8 -> 3 -> 12 -> 9 -> 17 -> 18 -> 23 -> 15
## 中序遍历实现
~~~java
class Solution {
private List<Integer> result = new ArrayList<>();
public List<Integer> inorderTraversal(TreeNode root) {
if (root == null) {
return new ArrayList<>();
}
if (root.left != null) {
inorderTraversal(root.left);
}
result.add(root.val);
if (root.right != null) {
inorderTraversal(root.right);
}
return result;
}
}
~~~
## 前序遍历实现
~~~java
class Solution {
private List<Integer> result = new LinkedList<>();
public List<Integer> preorderTraversal(TreeNode root) {
if (root == null) {
return new LinkedList<>();
}
result.add(root.val);
if (root.left != null) {
preorderTraversal(root.left);
}
if (root.right != null) {
preorderTraversal(root.right);
}
return result;
}
}
~~~
## 后续遍历实现
~~~java
class Solution {
private List<Integer> result = new LinkedList<>();
public List<Integer> postorderTraversal(TreeNode root) {
if (root == null) {
return new LinkedList<>();
}
if (root.left != null) {
postorderTraversal(root.left);
}
if (root.right != null) {
postorderTraversal(root.right);
}
result.add(root.val);
return result;
}
}
~~~
## 三种遍历方式的时间复杂度分析
对于一颗空树而言,三种遍历方式执行的都是:
~~~java
if (root == null) {
return new LinkedList<>();
}
~~~
可以视为常数时间,即:$T(0) = c$。
对于n>0的情况,假设当前节点的左边有k个节点,那么可以算出来该节点的右边有n-k-1个节点,因此运行时间符合下列算式:$T(n) \leqslant T(k) + T(n-k-1) + d$,其中常数d大于0。
$$
\begin{array}{l}
T(n) \leqslant T(k) + T(n-k-1) + d \\
= ((c + d)k + c) + ((c + d)(n - k - 1) + c) + d\\
= (c + d)n + c - (c + d) + c + d\\
= (c + d)n + c
\end{array}
$$
即$T(n) = O(n)$
> ~~~pseudocode
> INORDER-TREE-WALK(x)
> if x != NIL
> INORDER-TREE-WALK(x.left)
> print x.key
> INORDER-TREE-WALK(x.right)
> ~~~
>
> 定理:如果x是一棵有n个结点子树的根,那么调用INORDER-TREE-WALK(x)需要Θ(n)时间。[^ 2 ]
[^ 1 ]:Paul W. Purdom, Jr. and Cynthia A. Brown. *The Analysis of Algorithms*. Holt, Rinehart, and Winston, 1985.
[^ 2 ]: Michael O. Rabin. Probabilistic algorithms. In J. F. Traub, editor, Algorithms and Complexity: *New Directions and Recent Results*, pages 21-39. Academic Press, 1976.
@@ -0,0 +1,4 @@
{
"label": "剑指Offer",
"position": 2
}
+1 -1
View File
@@ -1,4 +1,4 @@
{
"label": "LeetCode刷题",
"position": 3
"position": 2
}
-4
View File
@@ -1,4 +0,0 @@
{
"label": "LeetCode刷题",
"position": 4
}
@@ -1,4 +1,4 @@
{
"label": "技术文档(后端)",
"position": 2
"position": 3
}
@@ -1,4 +1,4 @@
{
"label": "技术文档(前端)",
"position": 3
"position": 4
}
+97 -11
View File
@@ -6,30 +6,116 @@ sidebar_position: 1
欢迎来到这里 **Docusaurus in less than 1 minutes**.
## Getting Started
## 现在开始
Get started by **creating a new site**.
Or **try Docusaurus immediately** with **[new.docusaurus.io](https://new.docusaurus.io)**.
## Generate a new site
## 代码块
Generate a new Docusaurus site using the **classic template**:
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
<Tabs
defaultValue="js"
values={[
{ label: 'JavaScript', value: 'js', },
{ label: 'Python', value: 'py', },
{ label: 'Java', value: 'java', },
]
}>
<TabItem value="js">
```js
function helloWorld() {
console.log('Hello, world!');
}
```
</TabItem>
<TabItem value="py">
```py
def hello_world():
print 'Hello, world!'
```
</TabItem>
<TabItem value="java">
```java
class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello, World");
}
}
```
</TabItem>
</Tabs>
以上是一些语言的‘Hello World
JS**:
```jsx title="/src/components/HelloCodeTitle.js"
function HelloCodeTitle(props) {
return <h1>Hello, {props.name}</h1>;
}
```
shell**:
```shell
npx @docusaurus/init@latest init my-website classic
```
## Start your site
## 开启Code-Docs服务
Run the development server:
```shell
cd my-website
npx docusaurus start
```
Your site starts at `http://localhost:3000`.
Open `docs/getting-started.md` and edit some lines: the site **reloads automatically** and display your changes.
## 行公式 TeX(KaTeX)
公式:
https://github.com/remarkjs/remark-math .
语法:
https://katex.org/ .
**Fundamental Theorem of Calculus**
Let $f:[a,b] \to \R$ be Riemann integrable. Let $F:[a,b]\to\R$ be $F(x)=
\int_{a}^{x}f(t)dt$.
Then $$F$$ is continuous, and at all $x$ such that $f$ is continuous at $x$,
$F$ is differentiable at $x$ with $F'(x)=f(x)$.
### 科学公式 TeX(KaTeX)
$$E=mc^2$$
行内的公式$$E=mc^2$$行内的公式,行内的$$E=mc^2$$公式。
$$\(\sqrt{3x-1}+(1+x)^2\)$$
$$\sin(\alpha)^{\theta}=\sum_{i=0}^{n}(x^i + \cos(f))$$
Text
$$
\int_0^\infty f(x)dx
$$
More Text
MEISHI
+14
View File
@@ -1,4 +1,7 @@
/** @type {import('@docusaurus/types').DocusaurusConfig} */
const math = require('remark-math');
const katex = require('rehype-katex');
module.exports = {
title: 'CodeDocs 编程文档',
tagline: 'CodeDocs 编程文档 -- 这里是一些技术人的编程文档',
@@ -109,6 +112,15 @@ module.exports = {
copyright: `Copyright © ${new Date().getFullYear()} Code Docs, Inc. 一些技术人的编程文档网站.`,
},
},
stylesheets: [
{
href: 'https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css',
type: 'text/css',
integrity:
'sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X',
crossorigin: 'anonymous',
},
],
presets: [
[
'@docusaurus/preset-classic',
@@ -116,6 +128,8 @@ module.exports = {
docs: {
sidebarPath: require.resolve('./sidebars.js'),
// Please change this to your repo.
remarkPlugins: [math],
rehypePlugins: [katex],
editUrl:
'https://github.com/facebook/docusaurus/edit/master/website/',
},
+3 -1
View File
@@ -19,7 +19,9 @@
"@mdx-js/react": "^1.6.21",
"clsx": "^1.1.1",
"react": "^17.0.1",
"react-dom": "^17.0.1"
"react-dom": "^17.0.1",
"rehype-katex": "^4.0.0",
"remark-math": "^3.0.1"
},
"browserslist": {
"production": [