Skip to content

Commit

Permalink
Site updated: 2024-06-06 11:15:18
Browse files Browse the repository at this point in the history
  • Loading branch information
novelyear committed Jun 6, 2024
1 parent 581ef8d commit 44b0ee7
Show file tree
Hide file tree
Showing 13 changed files with 796 additions and 53 deletions.
2 changes: 1 addition & 1 deletion 2024/06/04/leetcode-day14/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta property="og:description" content="今日内容: 递归遍历 迭代遍历 统一迭代 三道例题: 前序遍历二叉树中序遍历二叉树后续遍历二叉树 递归遍历太过简单,skip 迭代遍历(非统一版)使用栈模拟递归过程: 前序就是先访问当前节点值,然后压栈右左孩子 123456789101112131415vector&lt;int&gt; preorderTraversal(TreeNode* root) &#123; if(roo">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2024-06-04T08:38:39.000Z">
<meta property="article:modified_time" content="2024-06-05T09:18:44.064Z">
<meta property="article:modified_time" content="2024-06-05T09:20:05.301Z">
<meta property="article:author" content="Leoo Yann">
<meta property="article:tag" content="leetcode">
<meta name="twitter:card" content="summary_large_image">
Expand Down
6 changes: 6 additions & 0 deletions 2024/06/05/leetcode-day15/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ <h1 id="对称二叉树"><a href="#对称二叉树" class="headerlink" title="
<article class="post-prev col-6">


<a href="/2024/06/06/leetcode-day16/" title="leetcode_day16">
<i class="iconfont icon-arrowleft"></i>
<span class="hidden-mobile">leetcode_day16</span>
<span class="visible-mobile">上一篇</span>
</a>

</article>
<article class="post-next col-6">

Expand Down
654 changes: 654 additions & 0 deletions 2024/06/06/leetcode-day16/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion archives/2024/05/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@


<div class="list-group">
<p class="h4">共计 12 篇文章</p>
<p class="h4">共计 13 篇文章</p>
<hr>


Expand Down
8 changes: 7 additions & 1 deletion archives/2024/06/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,20 @@


<div class="list-group">
<p class="h4">共计 12 篇文章</p>
<p class="h4">共计 13 篇文章</p>
<hr>




<p class="h5">2024</p>

<a href="/2024/06/06/leetcode-day16/" class="list-group-item list-group-item-action">
<time>06-06</time>
<div class="list-group-item-title">leetcode_day16</div>
</a>


<a href="/2024/06/05/leetcode-day15/" class="list-group-item list-group-item-action">
<time>06-05</time>
<div class="list-group-item-title">leetcode_day15</div>
Expand Down
14 changes: 7 additions & 7 deletions archives/2024/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,20 @@


<div class="list-group">
<p class="h4">共计 12 篇文章</p>
<p class="h4">共计 13 篇文章</p>
<hr>




<p class="h5">2024</p>

<a href="/2024/06/06/leetcode-day16/" class="list-group-item list-group-item-action">
<time>06-06</time>
<div class="list-group-item-title">leetcode_day16</div>
</a>


<a href="/2024/06/05/leetcode-day15/" class="list-group-item list-group-item-action">
<time>06-05</time>
<div class="list-group-item-title">leetcode_day15</div>
Expand Down Expand Up @@ -277,12 +283,6 @@
<div class="list-group-item-title">leetcode_day7</div>
</a>


<a href="/2024/05/27/%E8%BF%B7%E8%BF%AD%E9%A6%99%E7%9A%84%E8%AE%B0%E4%BA%8B%E6%9C%AC%EF%BC%9A%E6%80%8E%E4%B9%88%E5%86%99%E5%8D%9A%E5%AE%A2/" class="list-group-item list-group-item-action">
<time>05-27</time>
<div class="list-group-item-title">迷迭香的记事本:怎么写博客</div>
</a>

</div>


Expand Down
8 changes: 7 additions & 1 deletion archives/2024/page/2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,20 @@


<div class="list-group">
<p class="h4">共计 12 篇文章</p>
<p class="h4">共计 13 篇文章</p>
<hr>




<p class="h5">2024</p>

<a href="/2024/05/27/%E8%BF%B7%E8%BF%AD%E9%A6%99%E7%9A%84%E8%AE%B0%E4%BA%8B%E6%9C%AC%EF%BC%9A%E6%80%8E%E4%B9%88%E5%86%99%E5%8D%9A%E5%AE%A2/" class="list-group-item list-group-item-action">
<time>05-27</time>
<div class="list-group-item-title">迷迭香的记事本:怎么写博客</div>
</a>


<a href="/2024/05/23/leetcode-day2/" class="list-group-item list-group-item-action">
<time>05-23</time>
<div class="list-group-item-title">leetcode_day2</div>
Expand Down
14 changes: 7 additions & 7 deletions archives/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,20 @@


<div class="list-group">
<p class="h4">共计 12 篇文章</p>
<p class="h4">共计 13 篇文章</p>
<hr>




<p class="h5">2024</p>

<a href="/2024/06/06/leetcode-day16/" class="list-group-item list-group-item-action">
<time>06-06</time>
<div class="list-group-item-title">leetcode_day16</div>
</a>


<a href="/2024/06/05/leetcode-day15/" class="list-group-item list-group-item-action">
<time>06-05</time>
<div class="list-group-item-title">leetcode_day15</div>
Expand Down Expand Up @@ -277,12 +283,6 @@
<div class="list-group-item-title">leetcode_day7</div>
</a>


<a href="/2024/05/27/%E8%BF%B7%E8%BF%AD%E9%A6%99%E7%9A%84%E8%AE%B0%E4%BA%8B%E6%9C%AC%EF%BC%9A%E6%80%8E%E4%B9%88%E5%86%99%E5%8D%9A%E5%AE%A2/" class="list-group-item list-group-item-action">
<time>05-27</time>
<div class="list-group-item-title">迷迭香的记事本:怎么写博客</div>
</a>

</div>


Expand Down
8 changes: 7 additions & 1 deletion archives/page/2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,20 @@


<div class="list-group">
<p class="h4">共计 12 篇文章</p>
<p class="h4">共计 13 篇文章</p>
<hr>




<p class="h5">2024</p>

<a href="/2024/05/27/%E8%BF%B7%E8%BF%AD%E9%A6%99%E7%9A%84%E8%AE%B0%E4%BA%8B%E6%9C%AC%EF%BC%9A%E6%80%8E%E4%B9%88%E5%86%99%E5%8D%9A%E5%AE%A2/" class="list-group-item list-group-item-action">
<time>05-27</time>
<div class="list-group-item-title">迷迭香的记事本:怎么写博客</div>
</a>


<a href="/2024/05/23/leetcode-day2/" class="list-group-item list-group-item-action">
<time>05-23</time>
<div class="list-group-item-title">leetcode_day2</div>
Expand Down
73 changes: 40 additions & 33 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,46 @@



<div class="row mx-auto index-card">


<article class="col-12 col-md-12 mx-auto index-info">
<h2 class="index-header">

<a href="/2024/06/06/leetcode-day16/" target="_self">
leetcode_day16
</a>
</h2>


<a class="index-excerpt index-excerpt__noimg" href="/2024/06/06/leetcode-day16/" target="_self">
<div>
今日内容: - 104.二叉树的最大深度- 559.n叉树的最大深度- 111.二叉树的最小深度- 222.完全二叉树的节点个数 树的最大深度最大深度指从根到所有节点的长度中最长的那一个,换言之就是要找离根最远的节点然后返回到它的长度。 用dfs和bfs都行,分别代表递归前后序遍历和层序遍历,对于n叉树而言,仅仅是多比较几次而已,改写难度不大 下附对于n叉树的bfs遍历 123456789101
</div>
</a>

<div class="index-btm post-metas">

<div class="post-meta mr-3">
<i class="iconfont icon-date"></i>
<time datetime="2024-06-06 10:38" pubdate>
2024-06-06
</time>
</div>



<div class="post-meta">
<i class="iconfont icon-tags"></i>

<a href="/tags/leetcode/">#leetcode</a>

</div>

</div>
</article>
</div>

<div class="row mx-auto index-card">


Expand Down Expand Up @@ -566,39 +606,6 @@ <h2 class="index-header">
</article>
</div>

<div class="row mx-auto index-card">


<article class="col-12 col-md-12 mx-auto index-info">
<h2 class="index-header">

<a href="/2024/05/27/%E8%BF%B7%E8%BF%AD%E9%A6%99%E7%9A%84%E8%AE%B0%E4%BA%8B%E6%9C%AC%EF%BC%9A%E6%80%8E%E4%B9%88%E5%86%99%E5%8D%9A%E5%AE%A2/" target="_self">
迷迭香的记事本:怎么写博客
</a>
</h2>


<a class="index-excerpt index-excerpt__noimg" href="/2024/05/27/%E8%BF%B7%E8%BF%AD%E9%A6%99%E7%9A%84%E8%AE%B0%E4%BA%8B%E6%9C%AC%EF%BC%9A%E6%80%8E%E4%B9%88%E5%86%99%E5%8D%9A%E5%AE%A2/" target="_self">
<div>
写在前面目前,如果misery想要写一篇博客,本地步骤为: 打开创建在D:的blog文件夹 右键,git bash here,输入hexo new blog &#39;YOUR_BLOG_NAME&#39; 进入source\_post文件夹中,找到step2创建的YOUR_BLOG_NAME.md文件,用vscode打开,进行编辑 回到bash,输入hexo g重新生成静态页面,选择性输入he
</div>
</a>

<div class="index-btm post-metas">

<div class="post-meta mr-3">
<i class="iconfont icon-date"></i>
<time datetime="2024-05-27 15:45" pubdate>
2024-05-27
</time>
</div>



</div>
</article>
</div>



<nav aria-label="navigation">
Expand Down
19 changes: 19 additions & 0 deletions local-search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@



<entry>
<title>leetcode_day16</title>
<link href="/2024/06/06/leetcode-day16/"/>
<url>/2024/06/06/leetcode-day16/</url>

<content type="html"><![CDATA[<p>今日内容: </p><p><a href="https://leetcode.cn/problems/maximum-depth-of-binary-tree/">- 104.二叉树的最大深度</a><br><a href="https://leetcode.cn/problems/maximum-depth-of-n-ary-tree/description/">- 559.n叉树的最大深度</a><br><a href="https://leetcode.cn/problems/minimum-depth-of-binary-tree/description/">- 111.二叉树的最小深度</a><br><a href="https://leetcode.cn/problems/count-complete-tree-nodes/description/">- 222.完全二叉树的节点个数</a></p><h1 id="树的最大深度"><a href="#树的最大深度" class="headerlink" title="树的最大深度"></a>树的最大深度</h1><p>最大深度指从根到所有节点的长度中最长的那一个,换言之就是要找离根最远的节点然后返回到它的长度。</p><p>用dfs和bfs都行,分别代表递归前后序遍历和层序遍历,对于n叉树而言,仅仅是多比较几次而已,改写难度不大</p><p>下附对于n叉树的bfs遍历</p><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">maxDepth</span><span class="hljs-params">(Node* root)</span> </span>&#123;<br> queue&lt;Node *&gt; q;<br> <span class="hljs-keyword">if</span>(root) q.<span class="hljs-built_in">push</span>(root);<br> <span class="hljs-type">int</span> ans = <span class="hljs-number">0</span>;<br> <span class="hljs-keyword">while</span>(!q.<span class="hljs-built_in">empty</span>()) &#123;<br> <span class="hljs-type">int</span> size = q.<span class="hljs-built_in">size</span>();<br> <span class="hljs-keyword">for</span>(<span class="hljs-type">int</span> i = <span class="hljs-number">0</span>;i &lt; size;i++) &#123;<br> Node * cur = q.<span class="hljs-built_in">front</span>();<br> q.<span class="hljs-built_in">pop</span>();<br> <span class="hljs-keyword">for</span>(<span class="hljs-type">int</span> j = <span class="hljs-number">0</span>;j &lt; cur-&gt;children.<span class="hljs-built_in">size</span>();j++) &#123;<br> q.<span class="hljs-built_in">push</span>(cur-&gt;children[j]);<br> &#125;<br> &#125;<br> ans++;<br> &#125;<br> <span class="hljs-keyword">return</span> ans;<br>&#125;<br></code></pre></td></tr></table></figure><h1 id="二叉树的最小深度"><a href="#二叉树的最小深度" class="headerlink" title="二叉树的最小深度"></a>二叉树的最小深度</h1><p>最小深度需要注意,是从根到最近的<strong>叶子节点</strong>的距离,<strong>叶子节点</strong>指没有左右孩子的节点</p><p>所以在遍历时需要注意结束条件,对于层序遍历则判断当前节点是否是叶子,如果是就维护最小深度</p><p>对于递归遍历则根据子节点个数来分类处理,如果左右双全或双无,则直接递归;如果只有一个,就单独递归</p><p>下附递归遍历代码:</p><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">minDepth</span><span class="hljs-params">(TreeNode* root)</span> </span>&#123;<br> <span class="hljs-keyword">if</span>(!root) <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br> <br> <span class="hljs-type">int</span> left = <span class="hljs-built_in">minDepth</span>(root-&gt;left);<br> <span class="hljs-type">int</span> right = <span class="hljs-built_in">minDepth</span>(root-&gt;right);<br><br> <span class="hljs-keyword">if</span>(root-&gt;left == <span class="hljs-literal">nullptr</span> &amp;&amp; root-&gt;right) &#123;<br> <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> + right;<br> &#125;<br> <span class="hljs-keyword">if</span>(root-&gt;right == <span class="hljs-literal">nullptr</span> &amp;&amp; root-&gt;left) &#123;<br> <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> + left;<br> &#125;<br> <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> + <span class="hljs-built_in">min</span>(left, right);<br>&#125;<br></code></pre></td></tr></table></figure><p><em>留坑,lc的最快执行代码中在最后<code>return</code>前把<code>root</code>的左右都指<code>null</code>,意义不明,但是就是快,没想出来为什么</em></p><h1 id="完全二叉树的节点个数"><a href="#完全二叉树的节点个数" class="headerlink" title="完全二叉树的节点个数"></a>完全二叉树的节点个数</h1><p>用普通二叉树的遍历当然能做,只是不太好,还是用好完全二叉树的特性:<strong>非底层全满,底层从左往右堆</strong></p><p>所以完全二叉树的左右子树深度肯定是一样的,如果不一样,那么再递归,直到递归到完全二叉树或者细粒度足够小时的空节点</p><p>代码贴的carl的,原文链接:<a href="https://programmercarl.com/0222.%E5%AE%8C%E5%85%A8%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E8%8A%82%E7%82%B9%E4%B8%AA%E6%95%B0.html#%E6%80%9D%E8%B7%AF">代码随想录 | 完全二叉树的节点个数</a></p><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">countNodes</span><span class="hljs-params">(TreeNode* root)</span> </span>&#123;<br> <span class="hljs-keyword">if</span> (root == <span class="hljs-literal">nullptr</span>) <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br> TreeNode* left = root-&gt;left;<br> TreeNode* right = root-&gt;right;<br> <span class="hljs-type">int</span> leftDepth = <span class="hljs-number">0</span>, rightDepth = <span class="hljs-number">0</span>; <span class="hljs-comment">// 这里初始为0是有目的的,为了下面求指数方便</span><br> <span class="hljs-keyword">while</span> (left) &#123; <span class="hljs-comment">// 求左子树深度</span><br> left = left-&gt;left;<br> leftDepth++;<br> &#125;<br> <span class="hljs-keyword">while</span> (right) &#123; <span class="hljs-comment">// 求右子树深度</span><br> right = right-&gt;right;<br> rightDepth++;<br> &#125;<br> <span class="hljs-keyword">if</span> (leftDepth == rightDepth) &#123;<br> <span class="hljs-keyword">return</span> (<span class="hljs-number">2</span> &lt;&lt; leftDepth) - <span class="hljs-number">1</span>; <span class="hljs-comment">// 注意(2&lt;&lt;1) 相当于2^2,所以leftDepth初始为0</span><br> &#125;<br> <span class="hljs-keyword">return</span> <span class="hljs-built_in">countNodes</span>(root-&gt;left) + <span class="hljs-built_in">countNodes</span>(root-&gt;right) + <span class="hljs-number">1</span>;<br>&#125;<br></code></pre></td></tr></table></figure>]]></content>



<tags>

<tag>leetcode</tag>

</tags>

</entry>



<entry>
<title>leetcode_day15</title>
<link href="/2024/06/05/leetcode-day15/"/>
Expand Down
33 changes: 33 additions & 0 deletions page/2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,39 @@



<div class="row mx-auto index-card">


<article class="col-12 col-md-12 mx-auto index-info">
<h2 class="index-header">

<a href="/2024/05/27/%E8%BF%B7%E8%BF%AD%E9%A6%99%E7%9A%84%E8%AE%B0%E4%BA%8B%E6%9C%AC%EF%BC%9A%E6%80%8E%E4%B9%88%E5%86%99%E5%8D%9A%E5%AE%A2/" target="_self">
迷迭香的记事本:怎么写博客
</a>
</h2>


<a class="index-excerpt index-excerpt__noimg" href="/2024/05/27/%E8%BF%B7%E8%BF%AD%E9%A6%99%E7%9A%84%E8%AE%B0%E4%BA%8B%E6%9C%AC%EF%BC%9A%E6%80%8E%E4%B9%88%E5%86%99%E5%8D%9A%E5%AE%A2/" target="_self">
<div>
写在前面目前,如果misery想要写一篇博客,本地步骤为: 打开创建在D:的blog文件夹 右键,git bash here,输入hexo new blog &#39;YOUR_BLOG_NAME&#39; 进入source\_post文件夹中,找到step2创建的YOUR_BLOG_NAME.md文件,用vscode打开,进行编辑 回到bash,输入hexo g重新生成静态页面,选择性输入he
</div>
</a>

<div class="index-btm post-metas">

<div class="post-meta mr-3">
<i class="iconfont icon-date"></i>
<time datetime="2024-05-27 15:45" pubdate>
2024-05-27
</time>
</div>



</div>
</article>
</div>

<div class="row mx-auto index-card">


Expand Down
8 changes: 7 additions & 1 deletion tags/leetcode/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,20 @@


<div class="list-group">
<p class="h4">共计 7 篇文章</p>
<p class="h4">共计 8 篇文章</p>
<hr>




<p class="h5">2024</p>

<a href="/2024/06/06/leetcode-day16/" class="list-group-item list-group-item-action">
<time>06-06</time>
<div class="list-group-item-title">leetcode_day16</div>
</a>


<a href="/2024/06/05/leetcode-day15/" class="list-group-item list-group-item-action">
<time>06-05</time>
<div class="list-group-item-title">leetcode_day15</div>
Expand Down

0 comments on commit 44b0ee7

Please sign in to comment.