package leetcode;

/**
 * https://leetcode.com/problems/number-of-boomerangs/
 */
public class Problem447 {
    public int numberOfBoomerangs(int[][] points) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem447 prob = new Problem447();
        System.out.println(prob.numberOfBoomerangs(new int[][]{{0, 0}, {1, 0}, {2, 0}})); // 2
        System.out.println(prob.numberOfBoomerangs(new int[][]{{1, 4}, {0, 8}, {2, 8}, {4, 5}})); // 2
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashSet;%0Aimport java.util.Set;%0A%0A
 /**%0A * h
@@ -214,32 +214,2161 @@
     
-// TODO%0A        return 0
+Set%3CString%3E set = new HashSet%3C%3E();%0A        for (int i = 0; i %3C points.length; i++) %7B%0A            String key = points%5Bi%5D%5B0%5D + %22%7C%22 + points%5Bi%5D%5B1%5D;%0A            set.add(key);%0A        %7D%0A        int result = 0;%0A        for (int i = 0; i %3C points.length; i++) %7B%0A            int%5B%5D a = points%5Bi%5D;%0A            String keyA = a%5B0%5D + %22%7C%22 + a%5B1%5D;%0A            for (int j = 0; j %3C points.length; j++) %7B%0A                if (i == j) %7B%0A                    continue;%0A                %7D%0A                int%5B%5D b = points%5Bj%5D;%0A                String keyB = b%5B0%5D + %22%7C%22 + b%5B1%5D;%0A                int diffi = Math.abs(b%5B0%5D - a%5B0%5D);%0A                int diffj = Math.abs(b%5B1%5D - a%5B1%5D);%0A%0A                Set%3CString%3E keys = new HashSet%3C%3E();%0A%0A                String key1 = (a%5B0%5D + diffi) + %22%7C%22 + (a%5B1%5D + diffj);%0A                keys.add(key1);%0A                if (!key1.equals(keyB) && !key1.equals(keyA)) %7B%0A                    if (set.contains(key1)) %7B%0A                        result++;%0A                    %7D%0A                %7D%0A%0A                String key2 = (a%5B0%5D - diffi) + %22%7C%22 + (a%5B1%5D - diffj);%0A                if (!keys.contains(key2)) %7B%0A                    keys.add(key2);%0A                    if (!key2.equals(keyB) && !key2.equals(keyA)) %7B%0A                        if (set.contains(key2)) %7B%0A                            result++;%0A                        %7D%0A                    %7D%0A                %7D%0A%0A                String key3 = (a%5B0%5D + diffi) + %22%7C%22 + (a%5B1%5D - diffj);%0A                if (!keys.contains(key3)) %7B%0A                    keys.add(key3);%0A                    if (!key3.equals(keyB) && !key3.equals(keyA)) %7B%0A                        if (set.contains(key3)) %7B%0A                            result++;%0A                        %7D%0A                    %7D%0A                %7D%0A%0A                String key4 = (a%5B0%5D - diffi) + %22%7C%22 + (a%5B1%5D + diffj);%0A                if (!keys.contains(key4)) %7B%0A                    keys.add(key4);%0A                    if (!key4.equals(keyB) && !key4.equals(keyA)) %7B%0A                        if (set.contains(key4)) %7B%0A                            result++;%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return result
 ;%0A  
@@ -2655,20 +2655,134 @@
 5%7D%7D)); // 2%0A
+        System.out.println(prob.numberOfBoomerangs(new int%5B%5D%5B%5D%7B%7B0, 0%7D, %7B1, 0%7D, %7B-1, 0%7D, %7B0, 1%7D, %7B0, -1%7D%7D)); // 20%0A
     %7D%0A%7D%0A

Update problem 447