package leetcode;

/**
 * https://leetcode.com/problems/sentence-similarity-ii/
 */
public class Problem737 {
    public boolean areSentencesSimilarTwo(String[] words1, String[] words2, String[][] pairs) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem737 prob = new Problem737();
        System.out.println(prob.areSentencesSimilarTwo(
            new String[]{"great", "acting", "skills"},
            new String[]{"fine", "drama", "talent"},
            new String[][]{{"great", "good"}, {"fine", "good"}, {"acting","drama"}, {"skills","talent"}}
        )); // true
        System.out.println(prob.areSentencesSimilarTwo(
            new String[]{"great"},
            new String[]{"great"},
            new String[][]{}
        )); // true
        System.out.println(prob.areSentencesSimilarTwo(
            new String[]{"great"},
            new String[]{"fine"},
            new String[][]{{"great", "good"}, {"fine", "good"}}
        )); // true
        System.out.println(prob.areSentencesSimilarTwo(
            new String[]{"great"},
            new String[]{"great", "blah"},
            new String[][]{}
        )); // false
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -260,35 +260,1291 @@
     
-// TODO%0A        return fals
+if (words1.length != words2.length) %7B%0A            return false;%0A        %7D%0A        Map%3CString, String%3E map = new HashMap%3C%3E();%0A        for (String%5B%5D pair : pairs) %7B%0A            if (!map.containsKey(pair%5B0%5D)) %7B%0A                map.put(pair%5B0%5D, pair%5B0%5D);%0A            %7D%0A            if (!map.containsKey(pair%5B1%5D)) %7B%0A                map.put(pair%5B1%5D, pair%5B1%5D);%0A            %7D%0A            if (!find(map, pair%5B0%5D).equals(find(map, pair%5B1%5D))) %7B%0A                map.put(pair%5B0%5D, pair%5B1%5D);%0A            %7D%0A        %7D%0A        for (int i = 0; i %3C words1.length; i++) %7B%0A            String word1 = words1%5Bi%5D;%0A            String word2 = words2%5Bi%5D;%0A            if (word1.equals(word2)) %7B%0A                continue;%0A            %7D%0A            if (!map.containsKey(word1)) %7B%0A                return false;%0A            %7D%0A            if (!map.containsKey(word2)) %7B%0A                return false;%0A            %7D%0A            if (!find(map, word1).equals(find(map, word2))) %7B%0A                return false;%0A            %7D%0A        %7D%0A        return true;%0A    %7D%0A%0A    private static String find(Map%3CString, String%3E map, String word) %7B%0A        String key = word;%0A        String value = map.get(key);%0A        while (!key.equals(value)) %7B%0A            key = value;%0A            value = map.get(key);%0A        %7D%0A        return valu
 e;%0A 

Update problem 737