Minimum Index Sum of Two Lists
https://leetcode.com/problems/minimum-index-sum-of-two-lists/description/
Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.
You need to help them find out theircommon interestwith theleast list index sum. If there is a choice tie between answers, output all of them with no order requirement. You could assume there always exists an answer.
Thoughts
想找出相同的string并且加起来index最小。找是否用共同元素想到hash set/table, 又因为要记录index,于是用map.
Code
Analysis
做题耗时: 13min
时间复杂度O(mn), 空间O(n)
Last updated
Was this helpful?