Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a9afd4b

Browse files
feat: add solutions to lc problem: No.0447.Number of Boomerangs
1 parent 85501ea commit a9afd4b

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

‎solution/0400-0499/0447.Number of Boomerangs/README.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,45 @@ class Solution {
111111
}
112112
```
113113

114+
### **Go**
115+
116+
```go
117+
func numberOfBoomerangs(points [][]int) int {
118+
ans := 0
119+
for _, p := range points {
120+
cnt := make(map[int]int)
121+
for _, q := range points {
122+
cnt[(p[0]-q[0])*(p[0]-q[0])+(p[1]-q[1])*(p[1]-q[1])]++
123+
}
124+
for _, v := range cnt {
125+
ans += v * (v - 1)
126+
}
127+
}
128+
return ans
129+
}
130+
```
131+
132+
### **C++**
133+
134+
```cpp
135+
class Solution {
136+
public:
137+
int numberOfBoomerangs(vector<vector<int>>& points) {
138+
int ans = 0;
139+
for (const auto& p : points) {
140+
unordered_map<int, int> cnt;
141+
for (const auto& q : points) {
142+
++cnt[(p[0] - q[0]) * (p[0] - q[0]) + (p[1] - q[1]) * (p[1] - q[1])];
143+
}
144+
for (const auto& [_, v] : cnt) {
145+
ans += v * (v - 1);
146+
}
147+
}
148+
return ans;
149+
}
150+
};
151+
```
152+
114153
### **...**
115154
116155
```

‎solution/0400-0499/0447.Number of Boomerangs/README_EN.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,45 @@ class Solution {
9999
}
100100
```
101101

102+
### **Go**
103+
104+
```go
105+
func numberOfBoomerangs(points [][]int) int {
106+
ans := 0
107+
for _, p := range points {
108+
cnt := make(map[int]int)
109+
for _, q := range points {
110+
cnt[(p[0]-q[0])*(p[0]-q[0])+(p[1]-q[1])*(p[1]-q[1])]++
111+
}
112+
for _, v := range cnt {
113+
ans += v * (v - 1)
114+
}
115+
}
116+
return ans
117+
}
118+
```
119+
120+
### **C++**
121+
122+
```cpp
123+
class Solution {
124+
public:
125+
int numberOfBoomerangs(vector<vector<int>>& points) {
126+
int ans = 0;
127+
for (const auto& p : points) {
128+
unordered_map<int, int> cnt;
129+
for (const auto& q : points) {
130+
++cnt[(p[0] - q[0]) * (p[0] - q[0]) + (p[1] - q[1]) * (p[1] - q[1])];
131+
}
132+
for (const auto& [_, v] : cnt) {
133+
ans += v * (v - 1);
134+
}
135+
}
136+
return ans;
137+
}
138+
};
139+
```
140+
102141
### **...**
103142
104143
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int numberOfBoomerangs(vector<vector<int>>& points) {
4+
int ans = 0;
5+
for (const auto& p : points) {
6+
unordered_map<int, int> cnt;
7+
for (const auto& q : points) {
8+
++cnt[(p[0] - q[0]) * (p[0] - q[0]) + (p[1] - q[1]) * (p[1] - q[1])];
9+
}
10+
for (const auto& [_, v] : cnt) {
11+
ans += v * (v - 1);
12+
}
13+
}
14+
return ans;
15+
}
16+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
func numberOfBoomerangs(points [][]int) int {
2+
ans := 0
3+
for _, p := range points {
4+
cnt := make(map[int]int)
5+
for _, q := range points {
6+
cnt[(p[0]-q[0])*(p[0]-q[0])+(p[1]-q[1])*(p[1]-q[1])]++
7+
}
8+
for _, v := range cnt {
9+
ans += v * (v - 1)
10+
}
11+
}
12+
return ans
13+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /