Skip to content

Commit

Permalink
Site updated: 2024-01-19 11:07:04
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaibineric committed Jan 19, 2024
1 parent 0ba26a6 commit bad9119
Show file tree
Hide file tree
Showing 19 changed files with 1,303 additions and 84 deletions.
8 changes: 6 additions & 2 deletions 2024/01/01/leetcode/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<meta property="og:image" content="https://gitee.com/lihaibineric/picgo/raw/master/pic/image-20240118151406885.png">
<meta property="og:image" content="https://gitee.com/lihaibineric/picgo/raw/master/pic/image-20240118152000575.png">
<meta property="article:published_time" content="2024-01-01T13:15:17.000Z">
<meta property="article:modified_time" content="2024-01-18T07:20:16.206Z">
<meta property="article:modified_time" content="2024-01-18T07:41:03.261Z">
<meta property="article:author" content="Haibin Li">
<meta property="article:tag" content="算法题">
<meta property="article:tag" content="leetcode">
Expand Down Expand Up @@ -226,7 +226,7 @@



132 mins
137 mins

</span>

Expand Down Expand Up @@ -594,6 +594,10 @@ <h3 id="删除链表的倒数第n个结点">删除链表的倒数第N个结点</
<figure class="highlight dns"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs dns">输入:head = [<span class="hljs-number">1,2,3,4</span>,<span class="hljs-number">5</span>], n = <span class="hljs-number">2</span><br>输出:[<span class="hljs-number">1,2,3,5</span>]<br></code></pre></td></tr></table></figure>
<p><strong>示例 2:</strong></p>
<figure class="highlight inform7"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs inform7">输入:head = <span class="hljs-comment">[1]</span>, n = 1<br>输出:<span class="hljs-comment">[]</span><br></code></pre></td></tr></table></figure>
<p>思路:</p>
<p>遍历,用两个指针分别来记录</p>
<p>如果要删除倒数第n个节点,让fast移动n步,然后让fast和slow同时移动,直到fast指向链表末尾。删掉slow所指向的节点就可以了</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><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs CPP"><span class="hljs-keyword">class</span> <span class="hljs-title class_">Solution</span> &#123;<br><span class="hljs-keyword">public</span>:<br> <span class="hljs-function">ListNode* <span class="hljs-title">removeNthFromEnd</span><span class="hljs-params">(ListNode* head, <span class="hljs-type">int</span> n)</span> </span>&#123;<br> ListNode* dummyHead = <span class="hljs-keyword">new</span> <span class="hljs-built_in">ListNode</span>(<span class="hljs-number">0</span>);<br> dummyHead-&gt;next = head;<br> ListNode* slow = dummyHead;<br> ListNode* fast = dummyHead;<br> <span class="hljs-keyword">while</span>(n-- &amp;&amp; fast != <span class="hljs-literal">NULL</span>) &#123;<br> fast = fast-&gt;next;<br> &#125;<br> fast = fast-&gt;next; <span class="hljs-comment">// fast再提前走一步,因为需要让slow指向删除节点的上一个节点</span><br> <span class="hljs-keyword">while</span> (fast != <span class="hljs-literal">NULL</span>) &#123;<br> fast = fast-&gt;next;<br> slow = slow-&gt;next;<br> &#125;<br> slow-&gt;next = slow-&gt;next-&gt;next; <br> <br> <span class="hljs-comment">// ListNode *tmp = slow-&gt;next; C++释放内存的逻辑</span><br> <span class="hljs-comment">// slow-&gt;next = tmp-&gt;next;</span><br> <span class="hljs-comment">// delete nth;</span><br> <br> <span class="hljs-keyword">return</span> dummyHead-&gt;next;<br> &#125;<br>&#125;;<br></code></pre></td></tr></table></figure>
<h1 id="二叉树">二叉树</h1>
<h1 id="深搜回溯">深搜回溯</h1>
<h1 id="贪心算法">贪心算法</h1>
Expand Down
6 changes: 6 additions & 0 deletions 2024/01/16/rec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,12 @@ <h3 id="模型参数">模型参数</h3>
<article class="post-prev col-6">


<a href="/2024/01/19/docker/" title="【基础工具】Docker的使用">
<i class="iconfont icon-arrowleft"></i>
<span class="hidden-mobile">【基础工具】Docker的使用</span>
<span class="visible-mobile">Previous</span>
</a>

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

Expand Down
Loading

0 comments on commit bad9119

Please sign in to comment.