Skip to content

Commit cb2095c

Browse files
committed
Deployed fd4035a with MkDocs version: 1.0.4
1 parent 6598355 commit cb2095c

File tree

8 files changed

+91
-34
lines changed

8 files changed

+91
-34
lines changed

14_树与二叉树/btree.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
# -*- coding: utf-8 -*-
22

33

4+
from collections import deque
5+
6+
7+
class Queue(object): # 借助内置的 deque 我们可以迅速实现一个 Queue
8+
def __init__(self):
9+
self._items = deque()
10+
11+
def append(self, value):
12+
return self._items.append(value)
13+
14+
def pop(self):
15+
return self._items.popleft()
16+
17+
def empty(self):
18+
return len(self._items) == 0
19+
20+
21+
class Stack(object):
22+
def __init__(self):
23+
self._items = deque()
24+
25+
def push(self, value):
26+
return self._items.append(value)
27+
28+
def pop(self):
29+
return self._items.pop()
30+
31+
def empty(self):
32+
return len(self._items) == 0
33+
434

535
class BinTreeNode(object):
636
def __init__(self, data, left=None, right=None):
@@ -36,6 +66,19 @@ def preorder_trav(self, subtree):
3666
self.preorder_trav(subtree.left)
3767
self.preorder_trav(subtree.right)
3868

69+
def preorder_trav_use_stack(self, subtree):
70+
"""递归的方式其实是计算机帮我们实现了栈结构,我们可以自己显示的用栈来实现"""
71+
s = Stack()
72+
if subtree:
73+
s.push(subtree)
74+
while not s.empty():
75+
peek = s.pop()
76+
print(peek.data) # 注意这里我用了 print,你可以用 yield 产出值然后在调用的地方转成 list
77+
if subtree.left:
78+
s.push(subtree.left)
79+
if subtree.right:
80+
s.push(subtree.right)
81+
3982
def inorder_trav(self, subtree):
4083
if subtree is not None:
4184
self.preorder_trav(subtree.left)
@@ -90,6 +133,8 @@ def layer_trav_use_queue(self, subtree):
90133
btree = BinTree.build_from(node_list)
91134
print('====先序遍历=====')
92135
btree.preorder_trav(btree.root)
136+
print('====使用 stack 实现先序遍历=====')
137+
btree.preorder_trav(btree.root)
93138
print('====层序遍历=====')
94139
btree.layer_trav(btree.root)
95140
print('====用队列层序遍历=====')

14_树与二叉树/tree/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ <h1 id="_5">二叉树的表示</h1>
305305
self.root = root
306306
</code></pre>
307307

308-
<p>怎么构造上图中的二叉树呢,似乎其他课本没找到啥例子,我自己定义了一种方法,首先我们输入节点信息,仔细看下边代码,叶子节点的 left 和 right 都是 None,并且只有一个根节点 A:</p>
308+
<p>怎么构造上图中的二叉树呢,似乎其他课本没找到啥例子(有些例子是写了一堆嵌套节点来定义,很难搞清楚层次关系),我自己定义了一种方法,首先我们输入节点信息,仔细看下边代码,叶子节点的 left 和 right 都是 None,并且只有一个根节点 A:</p>
309309
<pre><code class="py">node_list = [
310310
{'data': 'A', 'left': 'B', 'right': 'C', 'is_root': True},
311311
{'data': 'B', 'left': 'D', 'right': 'E', 'is_root': False},
@@ -320,7 +320,7 @@ <h1 id="_5">二叉树的表示</h1>
320320
]
321321
</code></pre>
322322

323-
<p>然后我们给 BinTreeNode 定义一个 build_from 方法:</p>
323+
<p>然后我们给 BinTreeNode 定义一个 build_from 方法,当然你也可以定义一种自己的构造方法</p>
324324
<pre><code class="py">class BinTree(object):
325325
def __init__(self, root=None):
326326
self.root = root
@@ -420,7 +420,7 @@ <h1 id="_7">二叉树层序遍历</h1>
420420
<p>除了递归的方式遍历之外,我们还可以使用层序遍历的方式。层序遍历比较直白,就是从根节点开始按照一层一层的方式遍历节点。
421421
我们可以从根节点开始,之后把所有当前层的孩子都按照从左到右的顺序放到一个列表里,下一次遍历所有这些孩子就可以了。</p>
422422
<pre><code class="py"> def layer_trav(self, subtree):
423-
cur_nodes = [subtree]
423+
cur_nodes = [subtree] # current layer nodes
424424
next_nodes = []
425425
while cur_nodes or next_nodes:
426426
for node in cur_nodes:

15_堆与堆排序/heap_and_heapsort/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ <h1 id="_5">实现堆排序</h1>
349349
</code></pre>
350350

351351
<h1 id="python-heapq">python 里的 heapq</h1>
352-
<p>python 其实自带了 heapq 模块,用来实现堆的相关操作,原理是类似的。请你阅读相关文档并使用内置的 heapq 模块完成堆排序。</p>
352+
<p>python 其实自带了 heapq 模块,用来实现堆的相关操作,原理是类似的。请你阅读相关文档并使用内置的 heapq 模块完成堆排序。
353+
一般我们刷题或者写业务代码的时候,使用这个内置的 heapq 模块就够用了。</p>
353354
<h1 id="_6">练习题</h1>
354355
<ul>
355356
<li>这里我用最大堆实现了一个 heapsort_reverse 函数,请你实现一个正序排序的函数。似乎不止一种方式</li>

20_面试指南/interview/index.html

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,13 @@
178178
<li class="toctree-l2"><a href="#_2">白板编程</a></li>
179179

180180

181-
<li class="toctree-l2"><a href="#_3">结语</a></li>
181+
<li class="toctree-l2"><a href="#_3">手写代码注意事项</a></li>
182182

183183

184-
<li class="toctree-l2"><a href="#_4">延伸阅读</a></li>
184+
<li class="toctree-l2"><a href="#_4">结语</a></li>
185+
186+
187+
<li class="toctree-l2"><a href="#_5">延伸阅读</a></li>
185188

186189

187190
</ul>
@@ -240,10 +243,18 @@ <h1 id="_2">白板编程</h1>
240243
<li>想不起来的函数名写伪代码,一般面试官不会强制说让你记住每个 api 的名字</li>
241244
<li>如果有多余的时间(一般不会有)注意一些边界条件,防御性编程、代码风格、单元测试等东西,想好一些异常情况(空值、边界值等)的测试用例</li>
242245
</ul>
243-
<h1 id="_3">结语</h1>
246+
<h1 id="_3">手写代码注意事项</h1>
247+
<p>这里我就直接引用《剑指offer》里内容,大家写代码的时候可以多加注意,对于应对算法面试,如果准备时间比较多,推荐看下这本书,并且刷一下
248+
leetcode 上的基础题目练练手感。</p>
249+
<ul>
250+
<li>规范性:书写清晰、布局清晰、命令合理</li>
251+
<li>完整性:完成基本功能,考虑边界条件,做好错误处理</li>
252+
<li>鲁棒性:防御式编程,处理无效输入</li>
253+
</ul>
254+
<h1 id="_4">结语</h1>
244255
<p>这套教程列举的算法很有限,包括图算法、贪心,动态规划,分布式,机器学习算法等很多没有涉及到,因为它们确实需要读者更深入的理论基础,而且这套教程的目的也不是针对算法竞赛。
245256
不过了解了本教程涉及到的大部分算法是可以应付绝大多数的业务开发的。如果读者对算法有兴趣,本教程引用的几本参考书都可以去深入学习。希望本教程能对你学习算法、养成良好的思维方式和编码习惯等有所帮助。</p>
246-
<h1 id="_4">延伸阅读</h1>
257+
<h1 id="_5">延伸阅读</h1>
247258
<p>目前市面上有一些专门针对算法面试的书供大家参考,如果你正在准备算法面试,我强烈建议你看看下面的参考资料学习解题技巧:</p>
248259
<ul>
249260
<li><a href="https://zhuanlan.zhihu.com/p/35175401">那些年,我们一起跪过的算法题[视频]</a></li>

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,5 +528,5 @@ <h2 id="_20">本电子书制作和写作方式</h2>
528528

529529
<!--
530530
MkDocs version : 1.0.4
531-
Build Date UTC : 2018-12-18 11:06:36
531+
Build Date UTC : 2018-12-19 00:37:20
532532
-->

search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

sitemap.xml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,122 +2,122 @@
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
33
<url>
44
<loc>None</loc>
5-
<lastmod>2018-12-18</lastmod>
5+
<lastmod>2018-12-19</lastmod>
66
<changefreq>daily</changefreq>
77
</url>
88
<url>
99
<loc>None</loc>
10-
<lastmod>2018-12-18</lastmod>
10+
<lastmod>2018-12-19</lastmod>
1111
<changefreq>daily</changefreq>
1212
</url>
1313
<url>
1414
<loc>None</loc>
15-
<lastmod>2018-12-18</lastmod>
15+
<lastmod>2018-12-19</lastmod>
1616
<changefreq>daily</changefreq>
1717
</url>
1818
<url>
1919
<loc>None</loc>
20-
<lastmod>2018-12-18</lastmod>
20+
<lastmod>2018-12-19</lastmod>
2121
<changefreq>daily</changefreq>
2222
</url>
2323
<url>
2424
<loc>None</loc>
25-
<lastmod>2018-12-18</lastmod>
25+
<lastmod>2018-12-19</lastmod>
2626
<changefreq>daily</changefreq>
2727
</url>
2828
<url>
2929
<loc>None</loc>
30-
<lastmod>2018-12-18</lastmod>
30+
<lastmod>2018-12-19</lastmod>
3131
<changefreq>daily</changefreq>
3232
</url>
3333
<url>
3434
<loc>None</loc>
35-
<lastmod>2018-12-18</lastmod>
35+
<lastmod>2018-12-19</lastmod>
3636
<changefreq>daily</changefreq>
3737
</url>
3838
<url>
3939
<loc>None</loc>
40-
<lastmod>2018-12-18</lastmod>
40+
<lastmod>2018-12-19</lastmod>
4141
<changefreq>daily</changefreq>
4242
</url>
4343
<url>
4444
<loc>None</loc>
45-
<lastmod>2018-12-18</lastmod>
45+
<lastmod>2018-12-19</lastmod>
4646
<changefreq>daily</changefreq>
4747
</url>
4848
<url>
4949
<loc>None</loc>
50-
<lastmod>2018-12-18</lastmod>
50+
<lastmod>2018-12-19</lastmod>
5151
<changefreq>daily</changefreq>
5252
</url>
5353
<url>
5454
<loc>None</loc>
55-
<lastmod>2018-12-18</lastmod>
55+
<lastmod>2018-12-19</lastmod>
5656
<changefreq>daily</changefreq>
5757
</url>
5858
<url>
5959
<loc>None</loc>
60-
<lastmod>2018-12-18</lastmod>
60+
<lastmod>2018-12-19</lastmod>
6161
<changefreq>daily</changefreq>
6262
</url>
6363
<url>
6464
<loc>None</loc>
65-
<lastmod>2018-12-18</lastmod>
65+
<lastmod>2018-12-19</lastmod>
6666
<changefreq>daily</changefreq>
6767
</url>
6868
<url>
6969
<loc>None</loc>
70-
<lastmod>2018-12-18</lastmod>
70+
<lastmod>2018-12-19</lastmod>
7171
<changefreq>daily</changefreq>
7272
</url>
7373
<url>
7474
<loc>None</loc>
75-
<lastmod>2018-12-18</lastmod>
75+
<lastmod>2018-12-19</lastmod>
7676
<changefreq>daily</changefreq>
7777
</url>
7878
<url>
7979
<loc>None</loc>
80-
<lastmod>2018-12-18</lastmod>
80+
<lastmod>2018-12-19</lastmod>
8181
<changefreq>daily</changefreq>
8282
</url>
8383
<url>
8484
<loc>None</loc>
85-
<lastmod>2018-12-18</lastmod>
85+
<lastmod>2018-12-19</lastmod>
8686
<changefreq>daily</changefreq>
8787
</url>
8888
<url>
8989
<loc>None</loc>
90-
<lastmod>2018-12-18</lastmod>
90+
<lastmod>2018-12-19</lastmod>
9191
<changefreq>daily</changefreq>
9292
</url>
9393
<url>
9494
<loc>None</loc>
95-
<lastmod>2018-12-18</lastmod>
95+
<lastmod>2018-12-19</lastmod>
9696
<changefreq>daily</changefreq>
9797
</url>
9898
<url>
9999
<loc>None</loc>
100-
<lastmod>2018-12-18</lastmod>
100+
<lastmod>2018-12-19</lastmod>
101101
<changefreq>daily</changefreq>
102102
</url>
103103
<url>
104104
<loc>None</loc>
105-
<lastmod>2018-12-18</lastmod>
105+
<lastmod>2018-12-19</lastmod>
106106
<changefreq>daily</changefreq>
107107
</url>
108108
<url>
109109
<loc>None</loc>
110-
<lastmod>2018-12-18</lastmod>
110+
<lastmod>2018-12-19</lastmod>
111111
<changefreq>daily</changefreq>
112112
</url>
113113
<url>
114114
<loc>None</loc>
115-
<lastmod>2018-12-18</lastmod>
115+
<lastmod>2018-12-19</lastmod>
116116
<changefreq>daily</changefreq>
117117
</url>
118118
<url>
119119
<loc>None</loc>
120-
<lastmod>2018-12-18</lastmod>
120+
<lastmod>2018-12-19</lastmod>
121121
<changefreq>daily</changefreq>
122122
</url>
123123
</urlset>

sitemap.xml.gz

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)