mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-09 01:11:42 +08:00
存量题库数据更新
This commit is contained in:
@@ -1,22 +1,38 @@
|
||||
<p>Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.</p>
|
||||
<p>Given two arrays of strings <code>list1</code> and <code>list2</code>, find the <strong>common strings with the least index sum</strong>.</p>
|
||||
|
||||
<p>You need to help them find out their <b>common interest</b> with the <b>least list index sum</b>. If there is a choice tie between answers, output all of them with no order requirement. You could assume there always exists an answer.</p>
|
||||
<p>A <strong>common string</strong> is a string that appeared in both <code>list1</code> and <code>list2</code>.</p>
|
||||
|
||||
<p>A <strong>common string with the least index sum</strong> is a common string such that if it appeared at <code>list1[i]</code> and <code>list2[j]</code> then <code>i + j</code> should be the minimum value among all the other <strong>common strings</strong>.</p>
|
||||
|
||||
<p>Return <em>all the <strong>common strings with the least index sum</strong></em>. Return the answer in <strong>any order</strong>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["Piatti","The Grill at Torrey Pines","Hungry Hunter Steakhouse","Shogun"]
|
||||
<strong>Output:</strong> ["Shogun"]
|
||||
<strong>Explanation:</strong> The only restaurant they both like is "Shogun".
|
||||
<strong>Explanation:</strong> The only common string is "Shogun".
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["KFC","Shogun","Burger King"]
|
||||
<strong>Output:</strong> ["Shogun"]
|
||||
<strong>Explanation:</strong> The restaurant they both like and have the least index sum is "Shogun" with index sum 1 (0+1).
|
||||
<strong>Explanation:</strong> The common string with the least index sum is "Shogun" with index sum = (0 + 1) = 1.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> list1 = ["happy","sad","good"], list2 = ["sad","happy","good"]
|
||||
<strong>Output:</strong> ["sad","happy"]
|
||||
<strong>Explanation:</strong> There are three common strings:
|
||||
"happy" with index sum = (0 + 1) = 1.
|
||||
"sad" with index sum = (1 + 0) = 1.
|
||||
"good" with index sum = (2 + 2) = 4.
|
||||
The strings with the least index sum are "sad" and "happy".
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -26,6 +42,7 @@
|
||||
<li><code>1 <= list1.length, list2.length <= 1000</code></li>
|
||||
<li><code>1 <= list1[i].length, list2[i].length <= 30</code></li>
|
||||
<li><code>list1[i]</code> and <code>list2[i]</code> consist of spaces <code>' '</code> and English letters.</li>
|
||||
<li>All the stings of <code>list1</code> are <strong>unique</strong>.</li>
|
||||
<li>All the stings of <code>list2</code> are <strong>unique</strong>.</li>
|
||||
<li>All the strings of <code>list1</code> are <strong>unique</strong>.</li>
|
||||
<li>All the strings of <code>list2</code> are <strong>unique</strong>.</li>
|
||||
<li>There is at least a common string between <code>list1</code> and <code>list2</code>.</li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user