Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 94fa529

Browse files
🐱(hash): 599. 两个列表的最小索引总和
1 parent 2176982 commit 94fa529

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

‎docs/data-structure/hash/README.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,39 @@ class Solution(object):
663663
return max_length
664664
```
665665

666+
# 599. 两个列表的最小索引总和
667+
668+
[原题链接](https://leetcode-cn.com/problems/minimum-index-sum-of-two-lists/)
669+
670+
## 解一:哈希表
671+
672+
```python
673+
class Solution:
674+
def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]:
675+
table1 = dict()
676+
table2 = dict()
677+
length1 = len(list1)
678+
length2 = len(list2)
679+
for i in range(length1):
680+
word = list1[i]
681+
table1[word] = i
682+
683+
min_index = float('inf')
684+
for j in range(length2):
685+
word = list2[j]
686+
if word in table1:
687+
table2[word] = j + table1.get(word)
688+
if table2[word] < min_index:
689+
min_index = table2[word]
690+
691+
ans = []
692+
for k, v in table2.items():
693+
if v == min_index:
694+
ans.append(k)
695+
696+
return ans
697+
```
698+
666699
## 705. 设计哈希集合
667700

668701
[原题链接](https://leetcode-cn.com/problems/design-hashset/)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /