首页 > 代码库 > [LeetCode] 599. Minimum Index Sum of Two Lists
[LeetCode] 599. Minimum Index Sum of Two Lists
https://leetcode.com/problems/minimum-index-sum-of-two-lists/
public class Solution { public String[] findRestaurant(String[] list1, String[] list2) { int leastSum = Integer.MAX_VALUE; List<String> result = new ArrayList<>(); Map<String, Integer> map = new HashMap<>(); for (int i = 0; i < list1.length; i++) { map.put(list1[i], i); } for (int i = 0; i < list2.length; i++) { if (map.containsKey(list2[i])) { int value = http://www.mamicode.com/map.get(list2[i]) + i; if (leastSum > value) { leastSum = value; result = new ArrayList<>(); } if (leastSum == value) { result.add(list2[i]); } } } return result.toArray(new String[result.size()]); } }
[LeetCode] 599. Minimum Index Sum of Two Lists
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。