标签:ring least ret https lists ini public value targe
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 = 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
标签:ring least ret https lists ini public value targe
原文地址:http://www.cnblogs.com/chencode/p/minimum-index-sum-of-two-lists.html