Skip to content

Commit

Permalink
Site updated: 2024-03-02 15:09:21
Browse files Browse the repository at this point in the history
  • Loading branch information
oyoanan committed Mar 2, 2024
1 parent e1ecd5c commit 6b559c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions 2024/03/02/LeetCode01/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://an-hexo-blog.oss-cn-beijing.aliyuncs.com/img/202403021502005.jpeg">
<meta property="article:published_time" content="2024-03-02T06:53:55.000Z">
<meta property="article:modified_time" content="2024-03-02T07:05:54.384Z">
<meta property="article:modified_time" content="2024-03-02T07:08:28.272Z">
<meta property="article:author" content="An">
<meta property="article:tag" content="Python">
<meta property="article:tag" content="题库">
Expand Down Expand Up @@ -304,7 +304,7 @@ <h2 id="题解"><a href="#题解" class="headerlink" title="题解"></a>题解</
<h3 id="方法二:哈希表"><a href="#方法二:哈希表" class="headerlink" title="方法二:哈希表"></a>方法二:哈希表</h3><p>对于数组中的每一个数<code>x</code>,首先查询哈希表中是否存在<code>target-x</code>,如果存在则返回结果,不存在就将<code>x</code>插入到哈希表中,保证不会让<code>x</code>和自己匹配。</p>
<figure class="highlight python"><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></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">class</span> <span class="hljs-title class_">Solution</span>:<br> <span class="hljs-keyword">def</span> <span class="hljs-title function_">twoSum</span>(<span class="hljs-params">self,nums,target</span>):<br> hashtable = <span class="hljs-built_in">dict</span>()<br> <span class="hljs-keyword">for</span> i,num <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(nums):<br> num2 = target - num <br> <span class="hljs-built_in">print</span>(num,num2)<br> <span class="hljs-keyword">if</span> num2 <span class="hljs-keyword">in</span> hashtable:<br> <span class="hljs-keyword">return</span> [i,hashtable[num2]]<br> hashtable[num] = i<br> <span class="hljs-built_in">print</span>(hashtable)<br> <span class="hljs-keyword">return</span> [] <br></code></pre></td></tr></table></figure>

<h3 id="知识点"><a href="#知识点" class="headerlink" title="知识点"></a>知识点</h3><ul>
<h2 id="知识点"><a href="#知识点" class="headerlink" title="知识点"></a>知识点</h2><ul>
<li><p><strong>是否会报超出索引异常</strong></p>
<blockquote>
<p>在方法一的双层for循环中,假设<code>nums</code>为5个元素,当for的外层循环遍历到最后一个元素时,<code>i</code>为4,内层循环涉及到<code>for j in range(5,5)</code>,生成的序列将是空的。因此,<code>for j in range(5,5)</code> 实际上不会执行循环体内的任何代码,也不存在报错。在 Python 中,尝试访问超出数组(列表)索引的元素会引发错误。具体来说,如果尝试访问一个不存在的索引位置,Python 会抛出 <code>IndexError</code> 异常。</p>
Expand Down
32 changes: 16 additions & 16 deletions categories/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,22 @@

<div class="category row nomargin-x">
<a class="category-item collapsed
list-group-item category-item-action col-10 col-md-11 col-xm-11" title="LeetCode"
id="heading-071fda8ffed879b16c3308d2133bac46" role="tab" data-toggle="collapse" href="#collapse-071fda8ffed879b16c3308d2133bac46"
list-group-item category-item-action col-10 col-md-11 col-xm-11" title="其他"
id="heading-0d98c74797e49d00bcc4c17c9d557a2b" role="tab" data-toggle="collapse" href="#collapse-0d98c74797e49d00bcc4c17c9d557a2b"
aria-expanded="false"
>
LeetCode
其他
<span class="list-group-count"></span>
<i class="iconfont icon-arrowright"></i>
</a>

<a href="/categories/LeetCode/" class="category-count col-2 col-md-1 col-xm-1">
<a href="/categories/%E5%85%B6%E4%BB%96/" class="category-count col-2 col-md-1 col-xm-1">
<i class="iconfont icon-articles"></i>
<span>1</span>
</a>

<div class="category-collapse collapse " id="collapse-071fda8ffed879b16c3308d2133bac46"
role="tabpanel" aria-labelledby="heading-071fda8ffed879b16c3308d2133bac46">
<div class="category-collapse collapse " id="collapse-0d98c74797e49d00bcc4c17c9d557a2b"
role="tabpanel" aria-labelledby="heading-0d98c74797e49d00bcc4c17c9d557a2b">



Expand All @@ -253,10 +253,10 @@



<a href="/2024/03/02/LeetCode01/" title="LeetCode01:两数之和"
<a href="/2024/02/28/Test/" title="Test"
class="list-group-item list-group-item-action
">
<span class="category-post">LeetCode01:两数之和</span>
<span class="category-post">Test</span>
</a>


Expand All @@ -271,22 +271,22 @@

<div class="category row nomargin-x">
<a class="category-item collapsed
list-group-item category-item-action col-10 col-md-11 col-xm-11" title="其他"
id="heading-0d98c74797e49d00bcc4c17c9d557a2b" role="tab" data-toggle="collapse" href="#collapse-0d98c74797e49d00bcc4c17c9d557a2b"
list-group-item category-item-action col-10 col-md-11 col-xm-11" title="LeetCode"
id="heading-071fda8ffed879b16c3308d2133bac46" role="tab" data-toggle="collapse" href="#collapse-071fda8ffed879b16c3308d2133bac46"
aria-expanded="false"
>
其他
LeetCode
<span class="list-group-count"></span>
<i class="iconfont icon-arrowright"></i>
</a>

<a href="/categories/%E5%85%B6%E4%BB%96/" class="category-count col-2 col-md-1 col-xm-1">
<a href="/categories/LeetCode/" class="category-count col-2 col-md-1 col-xm-1">
<i class="iconfont icon-articles"></i>
<span>1</span>
</a>

<div class="category-collapse collapse " id="collapse-0d98c74797e49d00bcc4c17c9d557a2b"
role="tabpanel" aria-labelledby="heading-0d98c74797e49d00bcc4c17c9d557a2b">
<div class="category-collapse collapse " id="collapse-071fda8ffed879b16c3308d2133bac46"
role="tabpanel" aria-labelledby="heading-071fda8ffed879b16c3308d2133bac46">



Expand All @@ -295,10 +295,10 @@



<a href="/2024/02/28/Test/" title="Test"
<a href="/2024/03/02/LeetCode01/" title="LeetCode01:两数之和"
class="list-group-item list-group-item-action
">
<span class="category-post">Test</span>
<span class="category-post">LeetCode01:两数之和</span>
</a>


Expand Down
Loading

0 comments on commit 6b559c5

Please sign in to comment.