This commit is contained in:
krahets
2024-05-01 07:30:15 +08:00
parent 85f0bc4ed1
commit d246e08cc6
68 changed files with 220 additions and 220 deletions
@@ -3597,7 +3597,7 @@
<p>Given an integer array <code>nums</code> and a target element <code>target</code>, please search for two elements in the array whose "sum" equals <code>target</code>, and return their array indices. Any solution is acceptable.</p>
</div>
<h2 id="1041-linear-search-trading-time-for-space">10.4.1 &nbsp; Linear search: trading time for space<a class="headerlink" href="#1041-linear-search-trading-time-for-space" title="Permanent link">&para;</a></h2>
<p>Consider traversing all possible combinations directly. As shown in the Figure 10-9 , we initiate a two-layer loop, and in each round, we determine whether the sum of the two integers equals <code>target</code>. If so, we return their indices.</p>
<p>Consider traversing all possible combinations directly. As shown in Figure 10-9, we initiate a two-layer loop, and in each round, we determine whether the sum of the two integers equals <code>target</code>. If so, we return their indices.</p>
<p><a class="glightbox" href="../replace_linear_by_hashing.assets/two_sum_brute_force.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Linear search solution for two-sum problem" class="animation-figure" src="../replace_linear_by_hashing.assets/two_sum_brute_force.png" /></a></p>
<p align="center"> Figure 10-9 &nbsp; Linear search solution for two-sum problem </p>