deploy
Before Width: | Height: | Size: 215 KiB After Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 24 KiB |
|
@ -3442,9 +3442,9 @@
|
|||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">list.py</span><pre><span></span><code><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="c1"># 初始化列表</span>
|
||||
<a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="c1"># 无初始值</span>
|
||||
<a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a><span class="n">nums1</span><span class="p">:</span> <span class="n">nums</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
|
||||
<a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a><span class="n">nums1</span><span class="p">:</span> <span class="nb">list</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
|
||||
<a id="__codelineno-0-4" name="__codelineno-0-4" href="#__codelineno-0-4"></a><span class="c1"># 有初始值</span>
|
||||
<a id="__codelineno-0-5" name="__codelineno-0-5" href="#__codelineno-0-5"></a><span class="n">nums</span><span class="p">:</span> <span class="n">nums</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">]</span>
|
||||
<a id="__codelineno-0-5" name="__codelineno-0-5" href="#__codelineno-0-5"></a><span class="n">nums</span><span class="p">:</span> <span class="nb">list</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">]</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -4009,7 +4009,7 @@
|
|||
<div class="tabbed-content">
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">list.py</span><pre><span></span><code><a id="__codelineno-48-1" name="__codelineno-48-1" href="#__codelineno-48-1"></a><span class="c1"># 拼接两个列表</span>
|
||||
<a id="__codelineno-48-2" name="__codelineno-48-2" href="#__codelineno-48-2"></a><span class="n">nums1</span><span class="p">:</span> <span class="n">nums</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">6</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">9</span><span class="p">]</span>
|
||||
<a id="__codelineno-48-2" name="__codelineno-48-2" href="#__codelineno-48-2"></a><span class="n">nums1</span><span class="p">:</span> <span class="nb">list</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">6</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">9</span><span class="p">]</span>
|
||||
<a id="__codelineno-48-3" name="__codelineno-48-3" href="#__codelineno-48-3"></a><span class="n">nums</span> <span class="o">+=</span> <span class="n">nums1</span> <span class="c1"># 将列表 nums1 拼接到 nums 之后</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
|
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 9.4 KiB |
|
@ -3904,8 +3904,8 @@
|
|||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">n_queens.c</span><pre><span></span><code><a id="__codelineno-10-1" name="__codelineno-10-1" href="#__codelineno-10-1"></a><span class="cm">/* 回溯算法:N 皇后 */</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">backtrack</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">row</span><span class="p">,</span><span class="w"> </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="kt">char</span><span class="w"> </span><span class="n">state</span><span class="p">[</span><span class="n">MAX_N</span><span class="p">][</span><span class="n">MAX_N</span><span class="p">],</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">***</span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">resSize</span><span class="p">,</span><span class="w"> </span><span class="kt">bool</span><span class="w"> </span><span class="n">cols</span><span class="p">[</span><span class="n">MAX_N</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="kt">bool</span><span class="w"> </span><span class="n">diags1</span><span class="p">[</span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_N</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="kt">bool</span><span class="w"> </span><span class="n">diags2</span><span class="p">[</span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_N</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-10-2" name="__codelineno-10-2" href="#__codelineno-10-2"></a><span class="kt">void</span><span class="w"> </span><span class="nf">backtrack</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">row</span><span class="p">,</span><span class="w"> </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="kt">char</span><span class="w"> </span><span class="n">state</span><span class="p">[</span><span class="n">MAX_SIZE</span><span class="p">][</span><span class="n">MAX_SIZE</span><span class="p">],</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">***</span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">resSize</span><span class="p">,</span><span class="w"> </span><span class="kt">bool</span><span class="w"> </span><span class="n">cols</span><span class="p">[</span><span class="n">MAX_SIZE</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="kt">bool</span><span class="w"> </span><span class="n">diags1</span><span class="p">[</span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_SIZE</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="kt">bool</span><span class="w"> </span><span class="n">diags2</span><span class="p">[</span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_SIZE</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-10-4" name="__codelineno-10-4" href="#__codelineno-10-4"></a><span class="w"> </span><span class="c1">// 当放置完所有行时,记录解</span>
|
||||
<a id="__codelineno-10-5" name="__codelineno-10-5" href="#__codelineno-10-5"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">row</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="p">{</span>
|
||||
<a id="__codelineno-10-6" name="__codelineno-10-6" href="#__codelineno-10-6"></a><span class="w"> </span><span class="n">res</span><span class="p">[</span><span class="o">*</span><span class="n">resSize</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">**</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">n</span><span class="p">);</span>
|
||||
|
@ -3937,7 +3937,7 @@
|
|||
<a id="__codelineno-10-32" name="__codelineno-10-32" href="#__codelineno-10-32"></a>
|
||||
<a id="__codelineno-10-33" name="__codelineno-10-33" href="#__codelineno-10-33"></a><span class="cm">/* 求解 N 皇后 */</span>
|
||||
<a id="__codelineno-10-34" name="__codelineno-10-34" href="#__codelineno-10-34"></a><span class="kt">char</span><span class="w"> </span><span class="o">***</span><span class="nf">nQueens</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="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-35" name="__codelineno-10-35" href="#__codelineno-10-35"></a><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="n">state</span><span class="p">[</span><span class="n">MAX_N</span><span class="p">][</span><span class="n">MAX_N</span><span class="p">];</span>
|
||||
<a id="__codelineno-10-35" name="__codelineno-10-35" href="#__codelineno-10-35"></a><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="n">state</span><span class="p">[</span><span class="n">MAX_SIZE</span><span class="p">][</span><span class="n">MAX_SIZE</span><span class="p">];</span>
|
||||
<a id="__codelineno-10-36" name="__codelineno-10-36" href="#__codelineno-10-36"></a><span class="w"> </span><span class="c1">// 初始化 n*n 大小的棋盘,其中 'Q' 代表皇后,'#' 代表空位</span>
|
||||
<a id="__codelineno-10-37" name="__codelineno-10-37" href="#__codelineno-10-37"></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="mi">0</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="n">n</span><span class="p">;</span><span class="w"> </span><span class="o">++</span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-38" name="__codelineno-10-38" href="#__codelineno-10-38"></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">j</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">j</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="n">j</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
|
@ -3945,11 +3945,11 @@
|
|||
<a id="__codelineno-10-40" name="__codelineno-10-40" href="#__codelineno-10-40"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-41" name="__codelineno-10-41" href="#__codelineno-10-41"></a><span class="w"> </span><span class="n">state</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">n</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="sc">'\0'</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-42" name="__codelineno-10-42" href="#__codelineno-10-42"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-43" name="__codelineno-10-43" href="#__codelineno-10-43"></a><span class="w"> </span><span class="kt">bool</span><span class="w"> </span><span class="n">cols</span><span class="p">[</span><span class="n">MAX_N</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="nb">false</span><span class="p">};</span><span class="w"> </span><span class="c1">// 记录列是否有皇后</span>
|
||||
<a id="__codelineno-10-44" name="__codelineno-10-44" href="#__codelineno-10-44"></a><span class="w"> </span><span class="kt">bool</span><span class="w"> </span><span class="n">diags1</span><span class="p">[</span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_N</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="o">=</span><span class="w"> </span><span class="p">{</span><span class="nb">false</span><span class="p">};</span><span class="w"> </span><span class="c1">// 记录主对角线是否有皇后</span>
|
||||
<a id="__codelineno-10-45" name="__codelineno-10-45" href="#__codelineno-10-45"></a><span class="w"> </span><span class="kt">bool</span><span class="w"> </span><span class="n">diags2</span><span class="p">[</span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_N</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="o">=</span><span class="w"> </span><span class="p">{</span><span class="nb">false</span><span class="p">};</span><span class="w"> </span><span class="c1">// 记录副对角线是否有皇后</span>
|
||||
<a id="__codelineno-10-43" name="__codelineno-10-43" href="#__codelineno-10-43"></a><span class="w"> </span><span class="kt">bool</span><span class="w"> </span><span class="n">cols</span><span class="p">[</span><span class="n">MAX_SIZE</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="nb">false</span><span class="p">};</span><span class="w"> </span><span class="c1">// 记录列是否有皇后</span>
|
||||
<a id="__codelineno-10-44" name="__codelineno-10-44" href="#__codelineno-10-44"></a><span class="w"> </span><span class="kt">bool</span><span class="w"> </span><span class="n">diags1</span><span class="p">[</span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_SIZE</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="o">=</span><span class="w"> </span><span class="p">{</span><span class="nb">false</span><span class="p">};</span><span class="w"> </span><span class="c1">// 记录主对角线是否有皇后</span>
|
||||
<a id="__codelineno-10-45" name="__codelineno-10-45" href="#__codelineno-10-45"></a><span class="w"> </span><span class="kt">bool</span><span class="w"> </span><span class="n">diags2</span><span class="p">[</span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_SIZE</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="o">=</span><span class="w"> </span><span class="p">{</span><span class="nb">false</span><span class="p">};</span><span class="w"> </span><span class="c1">// 记录副对角线是否有皇后</span>
|
||||
<a id="__codelineno-10-46" name="__codelineno-10-46" href="#__codelineno-10-46"></a>
|
||||
<a id="__codelineno-10-47" name="__codelineno-10-47" href="#__codelineno-10-47"></a><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">***</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">***</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">**</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_RES</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-47" name="__codelineno-10-47" href="#__codelineno-10-47"></a><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">***</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">***</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">**</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_SIZE</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-48" name="__codelineno-10-48" href="#__codelineno-10-48"></a><span class="w"> </span><span class="o">*</span><span class="n">returnSize</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-10-49" name="__codelineno-10-49" href="#__codelineno-10-49"></a><span class="w"> </span><span class="n">backtrack</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">n</span><span class="p">,</span><span class="w"> </span><span class="n">state</span><span class="p">,</span><span class="w"> </span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="n">returnSize</span><span class="p">,</span><span class="w"> </span><span class="n">cols</span><span class="p">,</span><span class="w"> </span><span class="n">diags1</span><span class="p">,</span><span class="w"> </span><span class="n">diags2</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-50" name="__codelineno-10-50" href="#__codelineno-10-50"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">res</span><span class="p">;</span>
|
||||
|
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 193 KiB After Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 212 KiB After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 18 KiB |
|
@ -3768,7 +3768,7 @@
|
|||
<a id="__codelineno-10-21" name="__codelineno-10-21" href="#__codelineno-10-21"></a><span class="cm">/* 构建二叉树 */</span>
|
||||
<a id="__codelineno-10-22" name="__codelineno-10-22" href="#__codelineno-10-22"></a><span class="n">TreeNode</span><span class="w"> </span><span class="o">*</span><span class="nf">buildTree</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">preorder</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">preorderSize</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">inorder</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">inorderSize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-23" name="__codelineno-10-23" href="#__codelineno-10-23"></a><span class="w"> </span><span class="c1">// 初始化哈希表,存储 inorder 元素到索引的映射</span>
|
||||
<a id="__codelineno-10-24" name="__codelineno-10-24" href="#__codelineno-10-24"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">inorderMap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_N</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-24" name="__codelineno-10-24" href="#__codelineno-10-24"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">inorderMap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_SIZE</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-25" name="__codelineno-10-25" href="#__codelineno-10-25"></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="mi">0</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="n">inorderSize</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-10-26" name="__codelineno-10-26" href="#__codelineno-10-26"></a><span class="w"> </span><span class="n">inorderMap</span><span class="p">[</span><span class="n">inorder</span><span class="p">[</span><span class="n">i</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-10-27" name="__codelineno-10-27" href="#__codelineno-10-27"></a><span class="w"> </span><span class="p">}</span>
|
||||
|
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 22 KiB |