|
| 1 | +#================================================== |
| 2 | +#==> Title: |
| 3 | +#==> Author: Zhang zhen |
| 4 | +#==> Email: hustmatnoble.gmail.com |
| 5 | +#==> GitHub: https://github.com/MatNoble |
| 6 | +#==> Date: |
| 7 | +#================================================== |
| 8 | + |
| 9 | + |
| 10 | +from typing import List |
| 11 | +from collections import Counter |
| 12 | +class Solution: |
| 13 | + def numberOfBoomerangs(self, points: List[List[int]]) -> int: |
| 14 | + def dis(a, b): |
| 15 | + return (a[0]-b[0])**2+(a[1]-b[1])**2 |
| 16 | + count = 0 |
| 17 | + for a in points: |
| 18 | + dis_ = [] |
| 19 | + for b in points: |
| 20 | + dis_.append(dis(a, b)) |
| 21 | + dict = Counter(dis_) |
| 22 | + for val in dict.values(): |
| 23 | + if val > 1: |
| 24 | + count += val * (val-1) |
| 25 | + return count |
| 26 | + |
| 27 | +mat = Solution() |
| 28 | +points = [[1,1]] |
| 29 | +points = [[0,0],[1,0],[2,0]] |
| 30 | +# points = [[1,1],[2,2],[3,3]] |
| 31 | +mat.numberOfBoomerangs(points) |
0 commit comments