File tree 4 files changed +107
-0
lines changed
solution/0400-0499/0447.Number of Boomerangs
4 files changed +107
-0
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,45 @@ class Solution {
111
111
}
112
112
```
113
113
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
+
114
153
### **...**
115
154
116
155
```
Original file line number Diff line number Diff line change @@ -99,6 +99,45 @@ class Solution {
99
99
}
100
100
```
101
101
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
+
102
141
### **...**
103
142
104
143
```
Original file line number Diff line number Diff line change
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
+ };
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments