package leetcode;

/**
 * https://leetcode.com/problems/minimum-index-sum-of-two-lists/#/description
 */
public class Problem577 {
    public String[] findRestaurant(String[] list1, String[] list2) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem577 prob = new Problem577();
        System.out.println(prob.findRestaurant(
            new String[]{"Shogun", "Tapioca Express", "Burger King", "KFC"},
            new String[]{"Piatti", "The Grill at Torrey Pines", "Hungry Hunter Steakhouse", "Shogun"})); // Shogun
        System.out.println(prob.findRestaurant(
            new String[]{"Shogun", "Tapioca Express", "Burger King", "KFC"},
            new String[]{"KFC", "Shogun", "Burger King"})); // Shogun
    }
}

@@ -12,16 +12,141 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -330,567 +330,767 @@
     
-// TODO%0A        return null;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem577 prob = new Problem577();%0A        System.out.println(prob.findRestaurant(%0A            new String%5B%5D%7B%22Shogun%22, %22Tapioca Express%22, %22Burger King%22, %22KFC%22%7D,%0A            new String%5B%5D%7B%22Piatti%22, %22The Grill at Torrey Pines%22, %22Hungry Hunter Steakhouse%22, %22Shogun%22%7D)); // Shogun%0A        System.out.println(prob.findRestaurant(%0A            new String%5B%5D%7B%22Shogun%22, %22Tapioca Express%22, %22Burger King%22, %22KFC%22%7D,%0A            new String%5B%5D%7B%22KFC%22, %22Shogun%22, %22Burger King%22%7D)); // Shogun
+Map%3CString, Integer%3E map = new HashMap%3C%3E();%0A        for (int i = 0; i %3C list1.length; i++) %7B%0A            map.put(list1%5Bi%5D, i);%0A        %7D%0A        int min = 0;%0A        boolean init = true;%0A        List%3CString%3E result = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C list2.length; i++) %7B%0A            if (map.containsKey(list2%5Bi%5D)) %7B%0A                int sum = map.get(list2%5Bi%5D) + i;%0A                if ((min == 0 && init) %7C%7C min %3E sum) %7B%0A                    min = sum;%0A                    result = new ArrayList%3C%3E();%0A                    result.add(list2%5Bi%5D);%0A                    init = false;%0A                %7D else if (sum == min) %7B%0A                    result.add(list2%5Bi%5D);%0A                %7D%0A            %7D%0A        %7D%0A        return result.toArray(new String%5B0%5D);
 %0A   

Solve problem 577