mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-25 12:36:30 +08:00
deploy
This commit is contained in:
parent
b9e72e2b86
commit
55931131dc
9 changed files with 250 additions and 214 deletions
|
@ -3545,7 +3545,18 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">preorder_traversal_i_compact.c</span><pre><span></span><code><a id="__codelineno-10-1" name="__codelineno-10-1" href="#__codelineno-10-1"></a><span class="p">[</span><span class="n">class</span><span class="p">]{}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{</span><span class="n">preOrder</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">preorder_traversal_i_compact.c</span><pre><span></span><code><a id="__codelineno-10-1" name="__codelineno-10-1" href="#__codelineno-10-1"></a><span class="cm">/* 前序遍历:例题一 */</span>
|
||||
<a id="__codelineno-10-2" name="__codelineno-10-2" href="#__codelineno-10-2"></a><span class="kt">void</span><span class="w"> </span><span class="nf">preOrder</span><span class="p">(</span><span class="n">TreeNode</span><span class="w"> </span><span class="o">*</span><span class="n">root</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-3" name="__codelineno-10-3" href="#__codelineno-10-3"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">root</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-4" name="__codelineno-10-4" href="#__codelineno-10-4"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-5" name="__codelineno-10-5" href="#__codelineno-10-5"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-6" name="__codelineno-10-6" href="#__codelineno-10-6"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">root</span><span class="o">-></span><span class="n">val</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">7</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-7" name="__codelineno-10-7" href="#__codelineno-10-7"></a><span class="w"> </span><span class="c1">// 记录解</span>
|
||||
<a id="__codelineno-10-8" name="__codelineno-10-8" href="#__codelineno-10-8"></a><span class="w"> </span><span class="n">vectorPushback</span><span class="p">(</span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="n">root</span><span class="p">,</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">));</span>
|
||||
<a id="__codelineno-10-9" name="__codelineno-10-9" href="#__codelineno-10-9"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-10" name="__codelineno-10-10" href="#__codelineno-10-10"></a><span class="w"> </span><span class="n">preOrder</span><span class="p">(</span><span class="n">root</span><span class="o">-></span><span class="n">left</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-11" name="__codelineno-10-11" href="#__codelineno-10-11"></a><span class="w"> </span><span class="n">preOrder</span><span class="p">(</span><span class="n">root</span><span class="o">-></span><span class="n">right</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-12" name="__codelineno-10-12" href="#__codelineno-10-12"></a><span class="p">}</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
|
@ -4908,7 +4908,24 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">recursion.c</span><pre><span></span><code><a id="__codelineno-94-1" name="__codelineno-94-1" href="#__codelineno-94-1"></a><span class="p">[</span><span class="n">class</span><span class="p">]{}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{</span><span class="n">forLoopRecur</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">recursion.c</span><pre><span></span><code><a id="__codelineno-94-1" name="__codelineno-94-1" href="#__codelineno-94-1"></a><span class="cm">/* 使用迭代模拟递归 */</span>
|
||||
<a id="__codelineno-94-2" name="__codelineno-94-2" href="#__codelineno-94-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">forLoopRecur</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-94-3" name="__codelineno-94-3" href="#__codelineno-94-3"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">stack</span><span class="p">[</span><span class="mi">1000</span><span class="p">];</span><span class="w"> </span><span class="c1">// 借助一个大数组来模拟栈</span>
|
||||
<a id="__codelineno-94-4" name="__codelineno-94-4" href="#__codelineno-94-4"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">top</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-94-5" name="__codelineno-94-5" href="#__codelineno-94-5"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-94-6" name="__codelineno-94-6" href="#__codelineno-94-6"></a><span class="w"> </span><span class="c1">// 递:递归调用</span>
|
||||
<a id="__codelineno-94-7" name="__codelineno-94-7" href="#__codelineno-94-7"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">n</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">--</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-94-8" name="__codelineno-94-8" href="#__codelineno-94-8"></a><span class="w"> </span><span class="c1">// 通过“入栈操作”模拟“递”</span>
|
||||
<a id="__codelineno-94-9" name="__codelineno-94-9" href="#__codelineno-94-9"></a><span class="w"> </span><span class="n">stack</span><span class="p">[</span><span class="n">top</span><span class="o">++</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">i</span><span class="p">;</span>
|
||||
<a id="__codelineno-94-10" name="__codelineno-94-10" href="#__codelineno-94-10"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-94-11" name="__codelineno-94-11" href="#__codelineno-94-11"></a><span class="w"> </span><span class="c1">// 归:返回结果</span>
|
||||
<a id="__codelineno-94-12" name="__codelineno-94-12" href="#__codelineno-94-12"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="n">top</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-94-13" name="__codelineno-94-13" href="#__codelineno-94-13"></a><span class="w"> </span><span class="c1">// 通过“出栈操作”模拟“归”</span>
|
||||
<a id="__codelineno-94-14" name="__codelineno-94-14" href="#__codelineno-94-14"></a><span class="w"> </span><span class="n">res</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">stack</span><span class="p">[</span><span class="n">top</span><span class="o">--</span><span class="p">];</span>
|
||||
<a id="__codelineno-94-15" name="__codelineno-94-15" href="#__codelineno-94-15"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-94-16" name="__codelineno-94-16" href="#__codelineno-94-16"></a><span class="w"> </span><span class="c1">// res = 1+2+3+...+n</span>
|
||||
<a id="__codelineno-94-17" name="__codelineno-94-17" href="#__codelineno-94-17"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">res</span><span class="p">;</span>
|
||||
<a id="__codelineno-94-18" name="__codelineno-94-18" href="#__codelineno-94-18"></a><span class="p">}</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
|
@ -4366,31 +4366,35 @@ O(1) < O(\log n) < O(n) < O(n^2) < O(2^n) \newline
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">space_complexity.zig</span><pre><span></span><code><a id="__codelineno-47-1" name="__codelineno-47-1" href="#__codelineno-47-1"></a><span class="p">[</span><span class="n">class</span><span class="p">]{}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{</span><span class="n">function</span><span class="p">}</span>
|
||||
<a id="__codelineno-47-2" name="__codelineno-47-2" href="#__codelineno-47-2"></a>
|
||||
<a id="__codelineno-47-3" name="__codelineno-47-3" href="#__codelineno-47-3"></a><span class="c1">// 常数阶</span>
|
||||
<a id="__codelineno-47-4" name="__codelineno-47-4" href="#__codelineno-47-4"></a><span class="k">fn</span><span class="w"> </span><span class="n">constant</span><span class="p">(</span><span class="n">n</span><span class="o">:</span><span class="w"> </span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-47-5" name="__codelineno-47-5" href="#__codelineno-47-5"></a><span class="w"> </span><span class="c1">// 常量、变量、对象占用 O(1) 空间</span>
|
||||
<a id="__codelineno-47-6" name="__codelineno-47-6" href="#__codelineno-47-6"></a><span class="w"> </span><span class="kr">const</span><span class="w"> </span><span class="n">a</span><span class="o">:</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-7" name="__codelineno-47-7" href="#__codelineno-47-7"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">b</span><span class="o">:</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-8" name="__codelineno-47-8" href="#__codelineno-47-8"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">nums</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">_</span><span class="p">]</span><span class="kt">i32</span><span class="p">{</span><span class="mi">0</span><span class="p">}</span><span class="o">**</span><span class="mi">10000</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-9" name="__codelineno-47-9" href="#__codelineno-47-9"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">node</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">inc</span><span class="p">.</span><span class="n">ListNode</span><span class="p">(</span><span class="kt">i32</span><span class="p">){.</span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">};</span>
|
||||
<a id="__codelineno-47-10" name="__codelineno-47-10" href="#__codelineno-47-10"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">i</span><span class="o">:</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-11" name="__codelineno-47-11" href="#__codelineno-47-11"></a><span class="w"> </span><span class="c1">// 循环中的变量占用 O(1) 空间</span>
|
||||
<a id="__codelineno-47-12" name="__codelineno-47-12" href="#__codelineno-47-12"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">n</span><span class="p">)</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-47-13" name="__codelineno-47-13" href="#__codelineno-47-13"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">c</span><span class="o">:</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-14" name="__codelineno-47-14" href="#__codelineno-47-14"></a><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">c</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-15" name="__codelineno-47-15" href="#__codelineno-47-15"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-47-16" name="__codelineno-47-16" href="#__codelineno-47-16"></a><span class="w"> </span><span class="c1">// 循环中的函数占用 O(1) 空间</span>
|
||||
<a id="__codelineno-47-17" name="__codelineno-47-17" href="#__codelineno-47-17"></a><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-18" name="__codelineno-47-18" href="#__codelineno-47-18"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">n</span><span class="p">)</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-47-19" name="__codelineno-47-19" href="#__codelineno-47-19"></a><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">function</span><span class="p">();</span>
|
||||
<a id="__codelineno-47-20" name="__codelineno-47-20" href="#__codelineno-47-20"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-47-21" name="__codelineno-47-21" href="#__codelineno-47-21"></a><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">a</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-22" name="__codelineno-47-22" href="#__codelineno-47-22"></a><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-23" name="__codelineno-47-23" href="#__codelineno-47-23"></a><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">nums</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-24" name="__codelineno-47-24" href="#__codelineno-47-24"></a><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-25" name="__codelineno-47-25" href="#__codelineno-47-25"></a><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">space_complexity.zig</span><pre><span></span><code><a id="__codelineno-47-1" name="__codelineno-47-1" href="#__codelineno-47-1"></a><span class="c1">// 函数</span>
|
||||
<a id="__codelineno-47-2" name="__codelineno-47-2" href="#__codelineno-47-2"></a><span class="k">fn</span><span class="w"> </span><span class="n">function</span><span class="p">()</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-47-3" name="__codelineno-47-3" href="#__codelineno-47-3"></a><span class="w"> </span><span class="c1">// 执行某些操作</span>
|
||||
<a id="__codelineno-47-4" name="__codelineno-47-4" href="#__codelineno-47-4"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-5" name="__codelineno-47-5" href="#__codelineno-47-5"></a><span class="p">}</span>
|
||||
<a id="__codelineno-47-6" name="__codelineno-47-6" href="#__codelineno-47-6"></a>
|
||||
<a id="__codelineno-47-7" name="__codelineno-47-7" href="#__codelineno-47-7"></a><span class="c1">// 常数阶</span>
|
||||
<a id="__codelineno-47-8" name="__codelineno-47-8" href="#__codelineno-47-8"></a><span class="k">fn</span><span class="w"> </span><span class="n">constant</span><span class="p">(</span><span class="n">n</span><span class="o">:</span><span class="w"> </span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-47-9" name="__codelineno-47-9" href="#__codelineno-47-9"></a><span class="w"> </span><span class="c1">// 常量、变量、对象占用 O(1) 空间</span>
|
||||
<a id="__codelineno-47-10" name="__codelineno-47-10" href="#__codelineno-47-10"></a><span class="w"> </span><span class="kr">const</span><span class="w"> </span><span class="n">a</span><span class="o">:</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-11" name="__codelineno-47-11" href="#__codelineno-47-11"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">b</span><span class="o">:</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-12" name="__codelineno-47-12" href="#__codelineno-47-12"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">nums</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">_</span><span class="p">]</span><span class="kt">i32</span><span class="p">{</span><span class="mi">0</span><span class="p">}</span><span class="o">**</span><span class="mi">10000</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-13" name="__codelineno-47-13" href="#__codelineno-47-13"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">node</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">inc</span><span class="p">.</span><span class="n">ListNode</span><span class="p">(</span><span class="kt">i32</span><span class="p">){.</span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">};</span>
|
||||
<a id="__codelineno-47-14" name="__codelineno-47-14" href="#__codelineno-47-14"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">i</span><span class="o">:</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-15" name="__codelineno-47-15" href="#__codelineno-47-15"></a><span class="w"> </span><span class="c1">// 循环中的变量占用 O(1) 空间</span>
|
||||
<a id="__codelineno-47-16" name="__codelineno-47-16" href="#__codelineno-47-16"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">n</span><span class="p">)</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-47-17" name="__codelineno-47-17" href="#__codelineno-47-17"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">c</span><span class="o">:</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-18" name="__codelineno-47-18" href="#__codelineno-47-18"></a><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">c</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-19" name="__codelineno-47-19" href="#__codelineno-47-19"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-47-20" name="__codelineno-47-20" href="#__codelineno-47-20"></a><span class="w"> </span><span class="c1">// 循环中的函数占用 O(1) 空间</span>
|
||||
<a id="__codelineno-47-21" name="__codelineno-47-21" href="#__codelineno-47-21"></a><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-22" name="__codelineno-47-22" href="#__codelineno-47-22"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">n</span><span class="p">)</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-47-23" name="__codelineno-47-23" href="#__codelineno-47-23"></a><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">function</span><span class="p">();</span>
|
||||
<a id="__codelineno-47-24" name="__codelineno-47-24" href="#__codelineno-47-24"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-47-25" name="__codelineno-47-25" href="#__codelineno-47-25"></a><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">a</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-26" name="__codelineno-47-26" href="#__codelineno-47-26"></a><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-27" name="__codelineno-47-27" href="#__codelineno-47-27"></a><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">nums</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-28" name="__codelineno-47-28" href="#__codelineno-47-28"></a><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">;</span>
|
||||
<a id="__codelineno-47-29" name="__codelineno-47-29" href="#__codelineno-47-29"></a><span class="p">}</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -4521,7 +4521,7 @@
|
|||
<div class="highlight"><span class="filename">hash_map_chaining.c</span><pre><span></span><code><a id="__codelineno-10-1" name="__codelineno-10-1" href="#__codelineno-10-1"></a><span class="cm">/* 链表节点 */</span>
|
||||
<a id="__codelineno-10-2" name="__codelineno-10-2" href="#__codelineno-10-2"></a><span class="k">struct</span><span class="w"> </span><span class="nc">node</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-3" name="__codelineno-10-3" href="#__codelineno-10-3"></a><span class="w"> </span><span class="n">Pair</span><span class="w"> </span><span class="o">*</span><span class="n">pair</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-4" name="__codelineno-10-4" href="#__codelineno-10-4"></a><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">Node</span><span class="w"> </span><span class="o">*</span><span class="n">next</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-4" name="__codelineno-10-4" href="#__codelineno-10-4"></a><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">node</span><span class="w"> </span><span class="o">*</span><span class="n">next</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-5" name="__codelineno-10-5" href="#__codelineno-10-5"></a><span class="p">};</span>
|
||||
<a id="__codelineno-10-6" name="__codelineno-10-6" href="#__codelineno-10-6"></a>
|
||||
<a id="__codelineno-10-7" name="__codelineno-10-7" href="#__codelineno-10-7"></a><span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">node</span><span class="w"> </span><span class="n">Node</span><span class="p">;</span>
|
||||
|
|
|
@ -4261,94 +4261,98 @@
|
|||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">array_hash_map.swift</span><pre><span></span><code><a id="__codelineno-30-1" name="__codelineno-30-1" href="#__codelineno-30-1"></a><span class="cm">/* 键值对 */</span>
|
||||
<a id="__codelineno-30-2" name="__codelineno-30-2" href="#__codelineno-30-2"></a><span class="kd">class</span> <span class="nc">Pair</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-3" name="__codelineno-30-3" href="#__codelineno-30-3"></a> <span class="kd">var</span> <span class="nv">key</span><span class="p">:</span> <span class="nb">Int</span>
|
||||
<a id="__codelineno-30-4" name="__codelineno-30-4" href="#__codelineno-30-4"></a> <span class="kd">var</span> <span class="nv">val</span><span class="p">:</span> <span class="nb">String</span>
|
||||
<a id="__codelineno-30-2" name="__codelineno-30-2" href="#__codelineno-30-2"></a><span class="kd">class</span> <span class="nc">Pair</span><span class="p">:</span> <span class="nb">Equatable</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-3" name="__codelineno-30-3" href="#__codelineno-30-3"></a> <span class="kd">public</span> <span class="kd">var</span> <span class="nv">key</span><span class="p">:</span> <span class="nb">Int</span>
|
||||
<a id="__codelineno-30-4" name="__codelineno-30-4" href="#__codelineno-30-4"></a> <span class="kd">public</span> <span class="kd">var</span> <span class="nv">val</span><span class="p">:</span> <span class="nb">String</span>
|
||||
<a id="__codelineno-30-5" name="__codelineno-30-5" href="#__codelineno-30-5"></a>
|
||||
<a id="__codelineno-30-6" name="__codelineno-30-6" href="#__codelineno-30-6"></a> <span class="kd">init</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="nb">Int</span><span class="p">,</span> <span class="n">val</span><span class="p">:</span> <span class="nb">String</span><span class="p">)</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-6" name="__codelineno-30-6" href="#__codelineno-30-6"></a> <span class="kd">public</span> <span class="kd">init</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="nb">Int</span><span class="p">,</span> <span class="n">val</span><span class="p">:</span> <span class="nb">String</span><span class="p">)</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-7" name="__codelineno-30-7" href="#__codelineno-30-7"></a> <span class="kc">self</span><span class="p">.</span><span class="n">key</span> <span class="p">=</span> <span class="n">key</span>
|
||||
<a id="__codelineno-30-8" name="__codelineno-30-8" href="#__codelineno-30-8"></a> <span class="kc">self</span><span class="p">.</span><span class="n">val</span> <span class="p">=</span> <span class="n">val</span>
|
||||
<a id="__codelineno-30-9" name="__codelineno-30-9" href="#__codelineno-30-9"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-10" name="__codelineno-30-10" href="#__codelineno-30-10"></a><span class="p">}</span>
|
||||
<a id="__codelineno-30-11" name="__codelineno-30-11" href="#__codelineno-30-11"></a>
|
||||
<a id="__codelineno-30-12" name="__codelineno-30-12" href="#__codelineno-30-12"></a><span class="cm">/* 基于数组简易实现的哈希表 */</span>
|
||||
<a id="__codelineno-30-13" name="__codelineno-30-13" href="#__codelineno-30-13"></a><span class="kd">class</span> <span class="nc">ArrayHashMap</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-14" name="__codelineno-30-14" href="#__codelineno-30-14"></a> <span class="kd">private</span> <span class="kd">var</span> <span class="nv">buckets</span><span class="p">:</span> <span class="p">[</span><span class="n">Pair</span><span class="p">?]</span> <span class="p">=</span> <span class="p">[]</span>
|
||||
<a id="__codelineno-30-10" name="__codelineno-30-10" href="#__codelineno-30-10"></a>
|
||||
<a id="__codelineno-30-11" name="__codelineno-30-11" href="#__codelineno-30-11"></a> <span class="kd">public</span> <span class="kd">static</span> <span class="kd">func</span> <span class="p">==</span> <span class="p">(</span><span class="n">lhs</span><span class="p">:</span> <span class="n">Pair</span><span class="p">,</span> <span class="n">rhs</span><span class="p">:</span> <span class="n">Pair</span><span class="p">)</span> <span class="p">-></span> <span class="nb">Bool</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-12" name="__codelineno-30-12" href="#__codelineno-30-12"></a> <span class="n">lhs</span><span class="p">.</span><span class="n">key</span> <span class="p">==</span> <span class="n">rhs</span><span class="p">.</span><span class="n">key</span> <span class="o">&&</span> <span class="n">lhs</span><span class="p">.</span><span class="n">val</span> <span class="p">==</span> <span class="n">rhs</span><span class="p">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-30-13" name="__codelineno-30-13" href="#__codelineno-30-13"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-14" name="__codelineno-30-14" href="#__codelineno-30-14"></a><span class="p">}</span>
|
||||
<a id="__codelineno-30-15" name="__codelineno-30-15" href="#__codelineno-30-15"></a>
|
||||
<a id="__codelineno-30-16" name="__codelineno-30-16" href="#__codelineno-30-16"></a> <span class="kd">init</span><span class="p">()</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-17" name="__codelineno-30-17" href="#__codelineno-30-17"></a> <span class="c1">// 初始化数组,包含 100 个桶</span>
|
||||
<a id="__codelineno-30-18" name="__codelineno-30-18" href="#__codelineno-30-18"></a> <span class="k">for</span> <span class="kc">_</span> <span class="k">in</span> <span class="mi">0</span> <span class="p">..</span><span class="o"><</span> <span class="mi">100</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-19" name="__codelineno-30-19" href="#__codelineno-30-19"></a> <span class="n">buckets</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="kc">nil</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-20" name="__codelineno-30-20" href="#__codelineno-30-20"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-21" name="__codelineno-30-21" href="#__codelineno-30-21"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-22" name="__codelineno-30-22" href="#__codelineno-30-22"></a>
|
||||
<a id="__codelineno-30-23" name="__codelineno-30-23" href="#__codelineno-30-23"></a> <span class="cm">/* 哈希函数 */</span>
|
||||
<a id="__codelineno-30-24" name="__codelineno-30-24" href="#__codelineno-30-24"></a> <span class="kd">private</span> <span class="kd">func</span> <span class="nf">hashFunc</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="nb">Int</span><span class="p">)</span> <span class="p">-></span> <span class="nb">Int</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-25" name="__codelineno-30-25" href="#__codelineno-30-25"></a> <span class="kd">let</span> <span class="nv">index</span> <span class="p">=</span> <span class="n">key</span> <span class="o">%</span> <span class="mi">100</span>
|
||||
<a id="__codelineno-30-26" name="__codelineno-30-26" href="#__codelineno-30-26"></a> <span class="k">return</span> <span class="n">index</span>
|
||||
<a id="__codelineno-30-27" name="__codelineno-30-27" href="#__codelineno-30-27"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-28" name="__codelineno-30-28" href="#__codelineno-30-28"></a>
|
||||
<a id="__codelineno-30-29" name="__codelineno-30-29" href="#__codelineno-30-29"></a> <span class="cm">/* 查询操作 */</span>
|
||||
<a id="__codelineno-30-30" name="__codelineno-30-30" href="#__codelineno-30-30"></a> <span class="kd">func</span> <span class="nf">get</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="nb">Int</span><span class="p">)</span> <span class="p">-></span> <span class="nb">String</span><span class="p">?</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-31" name="__codelineno-30-31" href="#__codelineno-30-31"></a> <span class="kd">let</span> <span class="nv">index</span> <span class="p">=</span> <span class="n">hashFunc</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="n">key</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-32" name="__codelineno-30-32" href="#__codelineno-30-32"></a> <span class="kd">let</span> <span class="nv">pair</span> <span class="p">=</span> <span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]</span>
|
||||
<a id="__codelineno-30-33" name="__codelineno-30-33" href="#__codelineno-30-33"></a> <span class="k">return</span> <span class="n">pair</span><span class="p">?.</span><span class="n">val</span>
|
||||
<a id="__codelineno-30-34" name="__codelineno-30-34" href="#__codelineno-30-34"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-35" name="__codelineno-30-35" href="#__codelineno-30-35"></a>
|
||||
<a id="__codelineno-30-36" name="__codelineno-30-36" href="#__codelineno-30-36"></a> <span class="cm">/* 添加操作 */</span>
|
||||
<a id="__codelineno-30-37" name="__codelineno-30-37" href="#__codelineno-30-37"></a> <span class="kd">func</span> <span class="nf">put</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="nb">Int</span><span class="p">,</span> <span class="n">val</span><span class="p">:</span> <span class="nb">String</span><span class="p">)</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-38" name="__codelineno-30-38" href="#__codelineno-30-38"></a> <span class="kd">let</span> <span class="nv">pair</span> <span class="p">=</span> <span class="n">Pair</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span><span class="p">:</span> <span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-39" name="__codelineno-30-39" href="#__codelineno-30-39"></a> <span class="kd">let</span> <span class="nv">index</span> <span class="p">=</span> <span class="n">hashFunc</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="n">key</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-40" name="__codelineno-30-40" href="#__codelineno-30-40"></a> <span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> <span class="p">=</span> <span class="n">pair</span>
|
||||
<a id="__codelineno-30-41" name="__codelineno-30-41" href="#__codelineno-30-41"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-42" name="__codelineno-30-42" href="#__codelineno-30-42"></a>
|
||||
<a id="__codelineno-30-43" name="__codelineno-30-43" href="#__codelineno-30-43"></a> <span class="cm">/* 删除操作 */</span>
|
||||
<a id="__codelineno-30-44" name="__codelineno-30-44" href="#__codelineno-30-44"></a> <span class="kd">func</span> <span class="nf">remove</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="nb">Int</span><span class="p">)</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-45" name="__codelineno-30-45" href="#__codelineno-30-45"></a> <span class="kd">let</span> <span class="nv">index</span> <span class="p">=</span> <span class="n">hashFunc</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="n">key</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-46" name="__codelineno-30-46" href="#__codelineno-30-46"></a> <span class="c1">// 置为 nil ,代表删除</span>
|
||||
<a id="__codelineno-30-47" name="__codelineno-30-47" href="#__codelineno-30-47"></a> <span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> <span class="p">=</span> <span class="kc">nil</span>
|
||||
<a id="__codelineno-30-48" name="__codelineno-30-48" href="#__codelineno-30-48"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-49" name="__codelineno-30-49" href="#__codelineno-30-49"></a>
|
||||
<a id="__codelineno-30-50" name="__codelineno-30-50" href="#__codelineno-30-50"></a> <span class="cm">/* 获取所有键值对 */</span>
|
||||
<a id="__codelineno-30-51" name="__codelineno-30-51" href="#__codelineno-30-51"></a> <span class="kd">func</span> <span class="nf">pairSet</span><span class="p">()</span> <span class="p">-></span> <span class="p">[</span><span class="n">Pair</span><span class="p">]</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-52" name="__codelineno-30-52" href="#__codelineno-30-52"></a> <span class="kd">var</span> <span class="nv">pairSet</span><span class="p">:</span> <span class="p">[</span><span class="n">Pair</span><span class="p">]</span> <span class="p">=</span> <span class="p">[]</span>
|
||||
<a id="__codelineno-30-53" name="__codelineno-30-53" href="#__codelineno-30-53"></a> <span class="k">for</span> <span class="n">pair</span> <span class="k">in</span> <span class="n">buckets</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-54" name="__codelineno-30-54" href="#__codelineno-30-54"></a> <span class="k">if</span> <span class="kd">let</span> <span class="nv">pair</span> <span class="p">=</span> <span class="n">pair</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-55" name="__codelineno-30-55" href="#__codelineno-30-55"></a> <span class="n">pairSet</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">pair</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-56" name="__codelineno-30-56" href="#__codelineno-30-56"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-57" name="__codelineno-30-57" href="#__codelineno-30-57"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-58" name="__codelineno-30-58" href="#__codelineno-30-58"></a> <span class="k">return</span> <span class="n">pairSet</span>
|
||||
<a id="__codelineno-30-59" name="__codelineno-30-59" href="#__codelineno-30-59"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-60" name="__codelineno-30-60" href="#__codelineno-30-60"></a>
|
||||
<a id="__codelineno-30-61" name="__codelineno-30-61" href="#__codelineno-30-61"></a> <span class="cm">/* 获取所有键 */</span>
|
||||
<a id="__codelineno-30-62" name="__codelineno-30-62" href="#__codelineno-30-62"></a> <span class="kd">func</span> <span class="nf">keySet</span><span class="p">()</span> <span class="p">-></span> <span class="p">[</span><span class="nb">Int</span><span class="p">]</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-63" name="__codelineno-30-63" href="#__codelineno-30-63"></a> <span class="kd">var</span> <span class="nv">keySet</span><span class="p">:</span> <span class="p">[</span><span class="nb">Int</span><span class="p">]</span> <span class="p">=</span> <span class="p">[]</span>
|
||||
<a id="__codelineno-30-64" name="__codelineno-30-64" href="#__codelineno-30-64"></a> <span class="k">for</span> <span class="n">pair</span> <span class="k">in</span> <span class="n">buckets</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-65" name="__codelineno-30-65" href="#__codelineno-30-65"></a> <span class="k">if</span> <span class="kd">let</span> <span class="nv">pair</span> <span class="p">=</span> <span class="n">pair</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-66" name="__codelineno-30-66" href="#__codelineno-30-66"></a> <span class="n">keySet</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">pair</span><span class="p">.</span><span class="n">key</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-67" name="__codelineno-30-67" href="#__codelineno-30-67"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-68" name="__codelineno-30-68" href="#__codelineno-30-68"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-69" name="__codelineno-30-69" href="#__codelineno-30-69"></a> <span class="k">return</span> <span class="n">keySet</span>
|
||||
<a id="__codelineno-30-70" name="__codelineno-30-70" href="#__codelineno-30-70"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-71" name="__codelineno-30-71" href="#__codelineno-30-71"></a>
|
||||
<a id="__codelineno-30-72" name="__codelineno-30-72" href="#__codelineno-30-72"></a> <span class="cm">/* 获取所有值 */</span>
|
||||
<a id="__codelineno-30-73" name="__codelineno-30-73" href="#__codelineno-30-73"></a> <span class="kd">func</span> <span class="nf">valueSet</span><span class="p">()</span> <span class="p">-></span> <span class="p">[</span><span class="nb">String</span><span class="p">]</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-74" name="__codelineno-30-74" href="#__codelineno-30-74"></a> <span class="kd">var</span> <span class="nv">valueSet</span><span class="p">:</span> <span class="p">[</span><span class="nb">String</span><span class="p">]</span> <span class="p">=</span> <span class="p">[]</span>
|
||||
<a id="__codelineno-30-75" name="__codelineno-30-75" href="#__codelineno-30-75"></a> <span class="k">for</span> <span class="n">pair</span> <span class="k">in</span> <span class="n">buckets</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-76" name="__codelineno-30-76" href="#__codelineno-30-76"></a> <span class="k">if</span> <span class="kd">let</span> <span class="nv">pair</span> <span class="p">=</span> <span class="n">pair</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-77" name="__codelineno-30-77" href="#__codelineno-30-77"></a> <span class="n">valueSet</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">pair</span><span class="p">.</span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-78" name="__codelineno-30-78" href="#__codelineno-30-78"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-79" name="__codelineno-30-79" href="#__codelineno-30-79"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-80" name="__codelineno-30-80" href="#__codelineno-30-80"></a> <span class="k">return</span> <span class="n">valueSet</span>
|
||||
<a id="__codelineno-30-81" name="__codelineno-30-81" href="#__codelineno-30-81"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-82" name="__codelineno-30-82" href="#__codelineno-30-82"></a>
|
||||
<a id="__codelineno-30-83" name="__codelineno-30-83" href="#__codelineno-30-83"></a> <span class="cm">/* 打印哈希表 */</span>
|
||||
<a id="__codelineno-30-84" name="__codelineno-30-84" href="#__codelineno-30-84"></a> <span class="kd">func</span> <span class="nf">print</span><span class="p">()</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-85" name="__codelineno-30-85" href="#__codelineno-30-85"></a> <span class="k">for</span> <span class="n">pair</span> <span class="k">in</span> <span class="n">pairSet</span><span class="p">()</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-86" name="__codelineno-30-86" href="#__codelineno-30-86"></a> <span class="n">Swift</span><span class="p">.</span><span class="bp">print</span><span class="p">(</span><span class="s">"</span><span class="si">\(</span><span class="n">pair</span><span class="p">.</span><span class="n">key</span><span class="si">)</span><span class="s"> -> </span><span class="si">\(</span><span class="n">pair</span><span class="p">.</span><span class="n">val</span><span class="si">)</span><span class="s">"</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-87" name="__codelineno-30-87" href="#__codelineno-30-87"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-88" name="__codelineno-30-88" href="#__codelineno-30-88"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-89" name="__codelineno-30-89" href="#__codelineno-30-89"></a><span class="p">}</span>
|
||||
<a id="__codelineno-30-16" name="__codelineno-30-16" href="#__codelineno-30-16"></a><span class="cm">/* 基于数组简易实现的哈希表 */</span>
|
||||
<a id="__codelineno-30-17" name="__codelineno-30-17" href="#__codelineno-30-17"></a><span class="kd">class</span> <span class="nc">ArrayHashMap</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-18" name="__codelineno-30-18" href="#__codelineno-30-18"></a> <span class="kd">private</span> <span class="kd">var</span> <span class="nv">buckets</span><span class="p">:</span> <span class="p">[</span><span class="n">Pair</span><span class="p">?]</span> <span class="p">=</span> <span class="p">[]</span>
|
||||
<a id="__codelineno-30-19" name="__codelineno-30-19" href="#__codelineno-30-19"></a>
|
||||
<a id="__codelineno-30-20" name="__codelineno-30-20" href="#__codelineno-30-20"></a> <span class="kd">init</span><span class="p">()</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-21" name="__codelineno-30-21" href="#__codelineno-30-21"></a> <span class="c1">// 初始化数组,包含 100 个桶</span>
|
||||
<a id="__codelineno-30-22" name="__codelineno-30-22" href="#__codelineno-30-22"></a> <span class="k">for</span> <span class="kc">_</span> <span class="k">in</span> <span class="mi">0</span> <span class="p">..</span><span class="o"><</span> <span class="mi">100</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-23" name="__codelineno-30-23" href="#__codelineno-30-23"></a> <span class="n">buckets</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="kc">nil</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-24" name="__codelineno-30-24" href="#__codelineno-30-24"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-25" name="__codelineno-30-25" href="#__codelineno-30-25"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-26" name="__codelineno-30-26" href="#__codelineno-30-26"></a>
|
||||
<a id="__codelineno-30-27" name="__codelineno-30-27" href="#__codelineno-30-27"></a> <span class="cm">/* 哈希函数 */</span>
|
||||
<a id="__codelineno-30-28" name="__codelineno-30-28" href="#__codelineno-30-28"></a> <span class="kd">private</span> <span class="kd">func</span> <span class="nf">hashFunc</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="nb">Int</span><span class="p">)</span> <span class="p">-></span> <span class="nb">Int</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-29" name="__codelineno-30-29" href="#__codelineno-30-29"></a> <span class="kd">let</span> <span class="nv">index</span> <span class="p">=</span> <span class="n">key</span> <span class="o">%</span> <span class="mi">100</span>
|
||||
<a id="__codelineno-30-30" name="__codelineno-30-30" href="#__codelineno-30-30"></a> <span class="k">return</span> <span class="n">index</span>
|
||||
<a id="__codelineno-30-31" name="__codelineno-30-31" href="#__codelineno-30-31"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-32" name="__codelineno-30-32" href="#__codelineno-30-32"></a>
|
||||
<a id="__codelineno-30-33" name="__codelineno-30-33" href="#__codelineno-30-33"></a> <span class="cm">/* 查询操作 */</span>
|
||||
<a id="__codelineno-30-34" name="__codelineno-30-34" href="#__codelineno-30-34"></a> <span class="kd">func</span> <span class="nf">get</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="nb">Int</span><span class="p">)</span> <span class="p">-></span> <span class="nb">String</span><span class="p">?</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-35" name="__codelineno-30-35" href="#__codelineno-30-35"></a> <span class="kd">let</span> <span class="nv">index</span> <span class="p">=</span> <span class="n">hashFunc</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="n">key</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-36" name="__codelineno-30-36" href="#__codelineno-30-36"></a> <span class="kd">let</span> <span class="nv">pair</span> <span class="p">=</span> <span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]</span>
|
||||
<a id="__codelineno-30-37" name="__codelineno-30-37" href="#__codelineno-30-37"></a> <span class="k">return</span> <span class="n">pair</span><span class="p">?.</span><span class="n">val</span>
|
||||
<a id="__codelineno-30-38" name="__codelineno-30-38" href="#__codelineno-30-38"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-39" name="__codelineno-30-39" href="#__codelineno-30-39"></a>
|
||||
<a id="__codelineno-30-40" name="__codelineno-30-40" href="#__codelineno-30-40"></a> <span class="cm">/* 添加操作 */</span>
|
||||
<a id="__codelineno-30-41" name="__codelineno-30-41" href="#__codelineno-30-41"></a> <span class="kd">func</span> <span class="nf">put</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="nb">Int</span><span class="p">,</span> <span class="n">val</span><span class="p">:</span> <span class="nb">String</span><span class="p">)</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-42" name="__codelineno-30-42" href="#__codelineno-30-42"></a> <span class="kd">let</span> <span class="nv">pair</span> <span class="p">=</span> <span class="n">Pair</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span><span class="p">:</span> <span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-43" name="__codelineno-30-43" href="#__codelineno-30-43"></a> <span class="kd">let</span> <span class="nv">index</span> <span class="p">=</span> <span class="n">hashFunc</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="n">key</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-44" name="__codelineno-30-44" href="#__codelineno-30-44"></a> <span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> <span class="p">=</span> <span class="n">pair</span>
|
||||
<a id="__codelineno-30-45" name="__codelineno-30-45" href="#__codelineno-30-45"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-46" name="__codelineno-30-46" href="#__codelineno-30-46"></a>
|
||||
<a id="__codelineno-30-47" name="__codelineno-30-47" href="#__codelineno-30-47"></a> <span class="cm">/* 删除操作 */</span>
|
||||
<a id="__codelineno-30-48" name="__codelineno-30-48" href="#__codelineno-30-48"></a> <span class="kd">func</span> <span class="nf">remove</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="nb">Int</span><span class="p">)</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-49" name="__codelineno-30-49" href="#__codelineno-30-49"></a> <span class="kd">let</span> <span class="nv">index</span> <span class="p">=</span> <span class="n">hashFunc</span><span class="p">(</span><span class="n">key</span><span class="p">:</span> <span class="n">key</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-50" name="__codelineno-30-50" href="#__codelineno-30-50"></a> <span class="c1">// 置为 nil ,代表删除</span>
|
||||
<a id="__codelineno-30-51" name="__codelineno-30-51" href="#__codelineno-30-51"></a> <span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> <span class="p">=</span> <span class="kc">nil</span>
|
||||
<a id="__codelineno-30-52" name="__codelineno-30-52" href="#__codelineno-30-52"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-53" name="__codelineno-30-53" href="#__codelineno-30-53"></a>
|
||||
<a id="__codelineno-30-54" name="__codelineno-30-54" href="#__codelineno-30-54"></a> <span class="cm">/* 获取所有键值对 */</span>
|
||||
<a id="__codelineno-30-55" name="__codelineno-30-55" href="#__codelineno-30-55"></a> <span class="kd">func</span> <span class="nf">pairSet</span><span class="p">()</span> <span class="p">-></span> <span class="p">[</span><span class="n">Pair</span><span class="p">]</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-56" name="__codelineno-30-56" href="#__codelineno-30-56"></a> <span class="kd">var</span> <span class="nv">pairSet</span><span class="p">:</span> <span class="p">[</span><span class="n">Pair</span><span class="p">]</span> <span class="p">=</span> <span class="p">[]</span>
|
||||
<a id="__codelineno-30-57" name="__codelineno-30-57" href="#__codelineno-30-57"></a> <span class="k">for</span> <span class="n">pair</span> <span class="k">in</span> <span class="n">buckets</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-58" name="__codelineno-30-58" href="#__codelineno-30-58"></a> <span class="k">if</span> <span class="kd">let</span> <span class="nv">pair</span> <span class="p">=</span> <span class="n">pair</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-59" name="__codelineno-30-59" href="#__codelineno-30-59"></a> <span class="n">pairSet</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">pair</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-60" name="__codelineno-30-60" href="#__codelineno-30-60"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-61" name="__codelineno-30-61" href="#__codelineno-30-61"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-62" name="__codelineno-30-62" href="#__codelineno-30-62"></a> <span class="k">return</span> <span class="n">pairSet</span>
|
||||
<a id="__codelineno-30-63" name="__codelineno-30-63" href="#__codelineno-30-63"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-64" name="__codelineno-30-64" href="#__codelineno-30-64"></a>
|
||||
<a id="__codelineno-30-65" name="__codelineno-30-65" href="#__codelineno-30-65"></a> <span class="cm">/* 获取所有键 */</span>
|
||||
<a id="__codelineno-30-66" name="__codelineno-30-66" href="#__codelineno-30-66"></a> <span class="kd">func</span> <span class="nf">keySet</span><span class="p">()</span> <span class="p">-></span> <span class="p">[</span><span class="nb">Int</span><span class="p">]</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-67" name="__codelineno-30-67" href="#__codelineno-30-67"></a> <span class="kd">var</span> <span class="nv">keySet</span><span class="p">:</span> <span class="p">[</span><span class="nb">Int</span><span class="p">]</span> <span class="p">=</span> <span class="p">[]</span>
|
||||
<a id="__codelineno-30-68" name="__codelineno-30-68" href="#__codelineno-30-68"></a> <span class="k">for</span> <span class="n">pair</span> <span class="k">in</span> <span class="n">buckets</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-69" name="__codelineno-30-69" href="#__codelineno-30-69"></a> <span class="k">if</span> <span class="kd">let</span> <span class="nv">pair</span> <span class="p">=</span> <span class="n">pair</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-70" name="__codelineno-30-70" href="#__codelineno-30-70"></a> <span class="n">keySet</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">pair</span><span class="p">.</span><span class="n">key</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-71" name="__codelineno-30-71" href="#__codelineno-30-71"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-72" name="__codelineno-30-72" href="#__codelineno-30-72"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-73" name="__codelineno-30-73" href="#__codelineno-30-73"></a> <span class="k">return</span> <span class="n">keySet</span>
|
||||
<a id="__codelineno-30-74" name="__codelineno-30-74" href="#__codelineno-30-74"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-75" name="__codelineno-30-75" href="#__codelineno-30-75"></a>
|
||||
<a id="__codelineno-30-76" name="__codelineno-30-76" href="#__codelineno-30-76"></a> <span class="cm">/* 获取所有值 */</span>
|
||||
<a id="__codelineno-30-77" name="__codelineno-30-77" href="#__codelineno-30-77"></a> <span class="kd">func</span> <span class="nf">valueSet</span><span class="p">()</span> <span class="p">-></span> <span class="p">[</span><span class="nb">String</span><span class="p">]</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-78" name="__codelineno-30-78" href="#__codelineno-30-78"></a> <span class="kd">var</span> <span class="nv">valueSet</span><span class="p">:</span> <span class="p">[</span><span class="nb">String</span><span class="p">]</span> <span class="p">=</span> <span class="p">[]</span>
|
||||
<a id="__codelineno-30-79" name="__codelineno-30-79" href="#__codelineno-30-79"></a> <span class="k">for</span> <span class="n">pair</span> <span class="k">in</span> <span class="n">buckets</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-80" name="__codelineno-30-80" href="#__codelineno-30-80"></a> <span class="k">if</span> <span class="kd">let</span> <span class="nv">pair</span> <span class="p">=</span> <span class="n">pair</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-81" name="__codelineno-30-81" href="#__codelineno-30-81"></a> <span class="n">valueSet</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">pair</span><span class="p">.</span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-82" name="__codelineno-30-82" href="#__codelineno-30-82"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-83" name="__codelineno-30-83" href="#__codelineno-30-83"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-84" name="__codelineno-30-84" href="#__codelineno-30-84"></a> <span class="k">return</span> <span class="n">valueSet</span>
|
||||
<a id="__codelineno-30-85" name="__codelineno-30-85" href="#__codelineno-30-85"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-86" name="__codelineno-30-86" href="#__codelineno-30-86"></a>
|
||||
<a id="__codelineno-30-87" name="__codelineno-30-87" href="#__codelineno-30-87"></a> <span class="cm">/* 打印哈希表 */</span>
|
||||
<a id="__codelineno-30-88" name="__codelineno-30-88" href="#__codelineno-30-88"></a> <span class="kd">func</span> <span class="nf">print</span><span class="p">()</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-89" name="__codelineno-30-89" href="#__codelineno-30-89"></a> <span class="k">for</span> <span class="n">pair</span> <span class="k">in</span> <span class="n">pairSet</span><span class="p">()</span> <span class="p">{</span>
|
||||
<a id="__codelineno-30-90" name="__codelineno-30-90" href="#__codelineno-30-90"></a> <span class="n">Swift</span><span class="p">.</span><span class="bp">print</span><span class="p">(</span><span class="s">"</span><span class="si">\(</span><span class="n">pair</span><span class="p">.</span><span class="n">key</span><span class="si">)</span><span class="s"> -> </span><span class="si">\(</span><span class="n">pair</span><span class="p">.</span><span class="n">val</span><span class="si">)</span><span class="s">"</span><span class="p">)</span>
|
||||
<a id="__codelineno-30-91" name="__codelineno-30-91" href="#__codelineno-30-91"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-92" name="__codelineno-30-92" href="#__codelineno-30-92"></a> <span class="p">}</span>
|
||||
<a id="__codelineno-30-93" name="__codelineno-30-93" href="#__codelineno-30-93"></a><span class="p">}</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 157 KiB After Width: | Height: | Size: 161 KiB |
File diff suppressed because one or more lines are too long
204
sitemap.xml
204
sitemap.xml
|
@ -2,512 +2,512 @@
|
|||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_appendix/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_appendix/contribution/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_appendix/installation/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/array/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/linked_list/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/list/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/backtracking_algorithm/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/n_queens_problem/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/permutations_problem/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/subset_sum_problem/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/iteration_and_recursion/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/performance_evaluation/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/space_complexity/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/time_complexity/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/basic_data_types/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/character_encoding/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/classification_of_data_structure/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/number_encoding/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/binary_search_recur/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/build_binary_tree_problem/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/divide_and_conquer/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/hanota_problem/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/dp_problem_features/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/dp_solution_pipeline/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/edit_distance_problem/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/intro_to_dynamic_programming/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/knapsack_problem/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/unbounded_knapsack_problem/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/graph/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/graph_operations/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/graph_traversal/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/fractional_knapsack_problem/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/greedy_algorithm/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/max_capacity_problem/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/max_product_cutting_problem/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/hash_algorithm/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/hash_collision/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/hash_map/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/build_heap/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/heap/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/top_k/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_introduction/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_introduction/algorithms_are_everywhere/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_introduction/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_introduction/what_is_dsa/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_preface/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_preface/about_the_book/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_preface/suggestions/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_preface/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_reference/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/binary_search/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/binary_search_edge/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/binary_search_insertion/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/replace_linear_by_hashing/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/searching_algorithm_revisited/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/bubble_sort/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/bucket_sort/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/counting_sort/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/heap_sort/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/insertion_sort/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/merge_sort/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/quick_sort/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/radix_sort/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/selection_sort/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/sorting_algorithm/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/deque/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/queue/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/stack/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/array_representation_of_tree/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/avl_tree/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/binary_search_tree/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/binary_tree/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/binary_tree_traversal/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/summary/</loc>
|
||||
<lastmod>2023-10-16</lastmod>
|
||||
<lastmod>2023-10-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
</urlset>
|
BIN
sitemap.xml.gz
BIN
sitemap.xml.gz
Binary file not shown.
Loading…
Reference in a new issue