提交 524a101f 编写于 作者: L luzhipeng

更新readme

上级 db3aee93
......@@ -19,6 +19,7 @@ leetcode 题解,记录自己的 leecode 解题之路。
## 食用指南
- 经典题目的解析的目录部分,前面有🆕的代表是最新更新的
- 对于最近更新的部分, 前面会有 🖊 标注
- 将来会在这里更新anki卡片
- 这里有一份leetcode官方账号在知乎上给出的一个《互联网公司最常见的面试算法题有哪些?》的答案,我这里尽量去覆盖回答中的题目和知识点
原文地址: https://www.zhihu.com/question/24964987/answer/586425979
......@@ -111,8 +112,8 @@ leetcode 题解,记录自己的 leecode 解题之路。
### 数据结构与算法的总结
- [basic-data-structure](./thinkings/basic-data-structure.md)(草稿)
- [binary-tree-traversal](./thinkings/binary-tree-traversal.md)
- 🖊 [basic-data-structure](./thinkings/basic-data-structure.md)(草稿)
- 🖊 [binary-tree-traversal](./thinkings/binary-tree-traversal.md)
- [dynamic-programming](./thinkings/dynamic-programming.md)
- [哈夫曼编码和游程编码](./thinkings/run-length-encode-and-huffman-encode.md)
- [布隆过滤器](./thinkings/bloom-filter.md)
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="408"
height="41"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.45"
sodipodi:docbase="/home/lasindi/Desktop"
sodipodi:docname="singly-linked-list.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
version="1.0"
sodipodi:modified="true">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
gridtolerance="10000"
guidetolerance="10"
objecttolerance="10"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8284272"
inkscape:cx="207.07407"
inkscape:cy="39.331288"
inkscape:document-units="px"
inkscape:current-layer="layer1"
inkscape:window-width="1600"
inkscape:window-height="1125"
inkscape:window-x="0"
inkscape:window-y="25"
width="350px"
height="60.000019px"
showgrid="false"
showguides="false" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
style="display:inline"
transform="translate(21.124908,-1018.9872)">
<rect
style="color:#000000;fill:#b3b3b3;fill-opacity:0;fill-rule:nonzero;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect2160"
width="40"
height="40"
x="-20.624908"
y="1019.4872" />
<text
xml:space="preserve"
style="font-size:25.22813034px;font-style:normal;font-weight:normal;text-align:center;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;display:inline;font-family:Bitstream Vera Sans"
x="-0.73485488"
y="1060.7592"
id="text4108"
transform="scale(1.0114576,0.9886722)"><tspan
sodipodi:role="line"
id="tspan4110"
x="-0.73485561"
y="1060.7592">12</tspan></text>
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 38.337482,1039.4872 C 98.000984,1039.4872 98.000984,1039.4872 98.000984,1039.4872"
id="path5097" />
<path
style="color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.99120814;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 98.676487,1039.4872 C 98.676487,1039.4872 95.287958,1040.4023 91.423343,1042.3636 C 87.558729,1044.3252 79.667695,1049.1349 79.667695,1049.1349 L 84.476723,1039.4872 L 79.667695,1029.8395 C 79.667695,1029.8395 87.558729,1034.6493 91.423343,1036.6109 C 95.287958,1038.5722 98.676487,1039.4872 98.676487,1039.4872 z "
id="path5099"
sodipodi:nodetypes="czccczc" />
<rect
style="color:#000000;fill:#b3b3b3;fill-opacity:0;fill-rule:nonzero;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect5282"
width="40"
height="40"
x="19.375092"
y="1019.4872" />
<rect
style="color:#000000;fill:#b3b3b3;fill-opacity:0;fill-rule:nonzero;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect9262"
width="40"
height="40"
x="100.37509"
y="1019.4872" />
<text
xml:space="preserve"
style="font-size:25.22813034px;font-style:normal;font-weight:normal;text-align:center;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;display:inline;font-family:Bitstream Vera Sans"
x="118.89449"
y="1060.7592"
id="text9264"
transform="scale(1.0114576,0.9886722)"><tspan
sodipodi:role="line"
id="tspan9266"
x="118.89449"
y="1060.7592">99</tspan></text>
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;display:inline"
d="M 159.33748,1039.4872 C 219.00098,1039.4872 219.00098,1039.4872 219.00098,1039.4872"
id="path9268" />
<path
style="color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.99120814;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 221.6762,1039.4872 C 221.6762,1039.4872 218.28767,1040.4023 214.42305,1042.3636 C 210.55844,1044.3252 202.66741,1049.1349 202.66741,1049.1349 L 207.47643,1039.4872 L 202.66741,1029.8395 C 202.66741,1029.8395 210.55844,1034.6493 214.42305,1036.6109 C 218.28767,1038.5722 221.6762,1039.4872 221.6762,1039.4872 z "
id="path9270"
sodipodi:nodetypes="czccczc" />
<rect
style="color:#000000;fill:#b3b3b3;fill-opacity:0;fill-rule:nonzero;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect9272"
width="40"
height="40"
x="140.37509"
y="1019.4872" />
<rect
style="color:#000000;fill:#b3b3b3;fill-opacity:0;fill-rule:nonzero;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect9276"
width="40"
height="40"
x="223.37509"
y="1019.4872" />
<text
xml:space="preserve"
style="font-size:25.22813034px;font-style:normal;font-weight:normal;text-align:center;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;display:inline;font-family:Bitstream Vera Sans"
x="240.50117"
y="1060.7592"
id="text9278"
transform="scale(1.0114576,0.9886722)"><tspan
sodipodi:role="line"
id="tspan9280"
x="240.50117"
y="1060.7592">37</tspan></text>
<rect
style="color:#000000;fill:#b3b3b3;fill-opacity:0;fill-rule:nonzero;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect9286"
width="40"
height="40"
x="263.37509"
y="1019.4872" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;display:inline"
d="M 282.33711,1039.4872 C 342.00061,1039.4872 342.00061,1039.4872 342.00061,1039.4872"
id="path2198" />
<path
style="color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.99120814;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 344.67583,1039.4872 C 344.67583,1039.4872 341.2873,1040.4023 337.42268,1042.3636 C 333.55807,1044.3252 325.66704,1049.1349 325.66704,1049.1349 L 330.47606,1039.4872 L 325.66704,1029.8395 C 325.66704,1029.8395 333.55807,1034.6493 337.42268,1036.6109 C 341.2873,1038.5722 344.67583,1039.4872 344.67583,1039.4872 z "
id="path2200"
sodipodi:nodetypes="czccczc" />
<g
id="g2213">
<rect
y="1019.4872"
x="346.37509"
height="40"
width="40"
id="rect2202"
style="color:#000000;fill:#b3b3b3;fill-opacity:0;fill-rule:nonzero;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
<path
id="path2209"
d="M 346.37509,1019.4872 C 385.97307,1059.0851 386.14985,1059.2619 386.14985,1059.2619"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path2211"
d="M 386.37509,1019.4872 C 346.77711,1059.0851 346.60033,1059.2619 346.60033,1059.2619"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;display:inline" />
</g>
<path
sodipodi:type="arc"
style="color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="path6449"
sodipodi:cx="21"
sodipodi:cy="18.5"
sodipodi:rx="6"
sodipodi:ry="6"
d="M 27 18.5 A 6 6 0 1 1 15,18.5 A 6 6 0 1 1 27 18.5 z"
transform="matrix(1,0,0,-1,18.375092,1057.9872)" />
<path
sodipodi:type="arc"
style="color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="path2339"
sodipodi:cx="21"
sodipodi:cy="18.5"
sodipodi:rx="6"
sodipodi:ry="6"
d="M 27 18.5 A 6 6 0 1 1 15,18.5 A 6 6 0 1 1 27 18.5 z"
transform="matrix(1,0,0,-1,139.37509,1057.9872)" />
<path
sodipodi:type="arc"
style="color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="path2341"
sodipodi:cx="21"
sodipodi:cy="18.5"
sodipodi:rx="6"
sodipodi:ry="6"
d="M 27 18.5 A 6 6 0 1 1 15,18.5 A 6 6 0 1 1 27 18.5 z"
transform="matrix(1,0,0,-1,262.37509,1057.9872)" />
</g>
</svg>
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1"
id="svg1430" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" inkscape:output_extension="org.inkscape.output.svg.inkscape" sodipodi:version="0.32" inkscape:version="0.46" sodipodi:docname="Data_queue.svg" sodipodi:docbase="/home/ubuuser"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="405px" height="265px"
viewBox="-30.228 18 405 265" enable-background="new -30.228 18 405 265" xml:space="preserve">
<defs>
<inkscape:perspective id="perspective2424" inkscape:vp_z="391.25 : 140.625 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_x="0 : 140.625 : 1" sodipodi:type="inkscape:persp3d" inkscape:persp3d-origin="195.625 : 93.75 : 1">
</inkscape:perspective>
</defs>
<sodipodi:namedview id="base" showgrid="false" inkscape:cx="167.43414" inkscape:zoom="2" borderopacity="1.0" bordercolor="#666666" pagecolor="#ffffff" inkscape:cy="160" inkscape:window-y="0" inkscape:window-x="0" inkscape:window-height="878" inkscape:window-width="1279" inkscape:current-layer="layer1" inkscape:document-units="px" inkscape:pageshadow="2" inkscape:pageopacity="0.0">
</sodipodi:namedview>
<rect id="node0" x="59" y="140.791" inkscape:label="#node1" transform="matrix(0.0043 1 -1 0.0043 256.347 51.1258)" fill="#0000FF" fill-opacity="0.75" stroke="#000000" width="87" height="27">
</rect>
<path id="path1446" sodipodi:arg2="0.33857128" sodipodi:arg1="-0.70862627" sodipodi:r2="4.6097722" sodipodi:r1="9.2195444" sodipodi:cy="278.36218" sodipodi:cx="353" sodipodi:sides="3" sodipodi:type="star" inkscape:randomized="0" inkscape:rounded="0" inkscape:flatsided="true" stroke="#000000" d="
M337.901,168.491l1.166,17.183l-10.081-13.992L337.901,168.491z"/>
<text transform="matrix(1 0 0 1 265.8555 145.0156)" font-family="'LucidaSans'" font-size="24">Dequeue</text>
<text transform="matrix(1 0 0 1 -24.2949 177.082)" font-family="'LucidaSans'" font-size="24">Enqueue</text>
<path id="path2432" fill="none" stroke="#000000" stroke-width="0.7364" d="M71.158,152.233L71.158,152.233
c-53.529-8.592-44.894-37.519-44.894-37.519"/>
<path id="path3204" fill="none" stroke="#000000" stroke-width="0.7313" d="M335.443,173.213L335.443,173.213
c-20.215-26.812-75.887-21.474-75.887-21.474"/>
<rect id="rect2481" x="94" y="140.791" inkscape:label="#node1" transform="matrix(0.0043 1 -1 0.0043 291.1959 16.1261)" fill="#0000FF" fill-opacity="0.75" stroke="#000000" width="87" height="27">
</rect>
<rect id="rect2483" x="129" y="140.791" inkscape:label="#node1" transform="matrix(0.0043 1 -1 0.0043 326.0458 -18.8727)" fill="#0000FF" fill-opacity="0.75" stroke="#000000" width="87" height="27">
</rect>
<rect id="rect2485" x="164" y="140.791" inkscape:label="#node1" transform="matrix(0.0043 1 -1 0.0043 360.895 -53.8723)" fill="#0000FF" fill-opacity="0.75" stroke="#000000" width="87" height="27">
</rect>
<rect id="rect2487" x="199" y="140.791" inkscape:label="#node1" transform="matrix(0.0043 1 -1 0.0043 395.7441 -88.872)" fill="#0000FF" fill-opacity="0.75" stroke="#000000" width="87" height="27">
</rect>
<path id="path2489" sodipodi:arg2="0.33857128" sodipodi:arg1="-0.70862627" sodipodi:r2="4.6097722" sodipodi:r1="9.2195444" sodipodi:cy="278.36218" sodipodi:cx="353" sodipodi:sides="3" sodipodi:type="star" inkscape:randomized="0" inkscape:rounded="0" inkscape:flatsided="true" stroke="#000000" d="
M65.739,147.016l16.555,4.748l-16.588,4.721L65.739,147.016z"/>
<rect id="rect2491" x="-16" y="52.75" inkscape:label="#node1" transform="matrix(0.0043 1 -1 0.0043 93.6309 38.4646)" fill="#0000FF" fill-opacity="0.75" stroke="#000000" width="87" height="27">
</rect>
<rect id="rect2493" x="299" y="221.25" inkscape:label="#node1" transform="matrix(0.0043 1 -1 0.0043 575.772 -108.7582)" fill="#0000FF" fill-opacity="0.75" stroke="#000000" width="87.001" height="27">
</rect>
<text transform="matrix(1 0 0 1 88.8125 101.5)" font-family="'LucidaSans'" font-size="20">Back</text>
<text transform="matrix(1 0 0 1 205.1035 101.5)" font-family="'LucidaSans'" font-size="20">Front</text>
</svg>
......@@ -65,15 +65,47 @@ hook2就是persistForm这个。
关于React hooks 的本质研究,更多请查看[React hooks: not magic, just arrays](https://medium.com/@ryardley/react-hooks-not-magic-just-arrays-cd4f1857236e)
### 队列
message queue
队列作为一种最常见的数据结构同样有着非常广泛的应用, 比如消息队列
> "队列"这个名称,可类比为现实生活中排队(不插队的那种)
在计算机科学中, 一个 队列(queue) 是一种特殊类型的抽象数据类型或集合。集合中的实体按顺序保存。
队列基本操作有两种:
- 向队列的后端位置添加实体,称为入队
- 从队列的前端位置移除实体,称为出队。
队列中元素先进先出 FIFO (first in, first out)的示意:
![basic-data-structure-queue](../assets/thinkings/basic-data-structure-queue.svg)
(图片来自 https://github.com/trekhleb/javascript-algorithms/blob/master/src/data-structures/queue/README.zh-CN.md)
### 栈
在计算机科学中, 一个 栈(stack) 是一种抽象数据类型,用作表示元素的集合,具有两种主要操作:
push, 添加元素到栈的顶端(末尾);
pop, 移除栈最顶端(末尾)的元素.
以上两种操作可以简单概括为“后进先出(LIFO = last in, first out)”。
此外,应有一个 peek 操作用于访问栈当前顶端(末尾)的元素。(只返回不弹出)
call stack, view stack
> "栈"这个名称,可类比于一组物体的堆叠(一摞书,一摞盘子之类的)。
其实浏览器的执行栈就是一个基本的栈结构,从数据结构上说,它就是一个栈。
栈的 push 和 pop 操作的示意:
![basic-data-structure-stack](../assets/thinkings/basic-data-structure-stack.png)
(图片来自 https://github.com/trekhleb/javascript-algorithms/blob/master/src/data-structures/stack/README.zh-CN.md)
栈在很多地方都有着应用,比如大家熟悉的浏览器就有很多栈,其实浏览器的执行栈就是一个基本的栈结构,从数据结构上说,它就是一个栈。
这也就解释了,我们用递归的解法和用循环+栈的解法本质上是差不多。
比如如下JS代码:
```js
......@@ -102,6 +134,12 @@ foo();
### 链表
链表是一种最基本数据结构,熟练掌握链表的结构和常见操作是基础中的基础。
![basic-data-structure-link-list](../assets/thinkings/basic-data-structure-link-list.svg)
(图片来自: https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/linked-list/traversal)
#### React Fiber
很多人都说 fiber 是基于链表实现的,但是为什么要基于链表呢,可能很多人并没有答案,那么我觉得可以把这两个点(fiber 和链表)放到一起来讲下。
......
......@@ -12,6 +12,12 @@ DFS 和 BFS 都有着自己的应用,比如 leetcode 301 号问题和 609 号
DFS 都可以使用栈来简化操作,并且其实树本身是一种递归的数据结构,因此递归和栈对于 DFS 来说是两个关键点。
DFS 图解:
![binary-tree-traversal-dfs](../assets/thinkings/binary-tree-traversal-dfs.gif)
(图片来自 https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/tree/depth-first-search)
BFS 的关键点在于如何记录每一层次是否遍历完成, 我们可以用一个标识位来表式当前层的结束。
下面我们依次讲解:
......@@ -66,6 +72,10 @@ BFS 的关键点在于如何记录每一层次是否遍历完成, 我们可以
层次遍历的关键点在于如何记录每一层次是否遍历完成, 我们可以用一个标识位来表式当前层的结束。
![binary-tree-traversal-bfs](../assets/thinkings/binary-tree-traversal-bfs.gif)
(图片来自 https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/tree/breadth-first-search)
具体做法:
1. 根节点入队列, 并入队列一个特殊的标识位,此处是 null
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册