Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
LeetCodeAnimation
Commits
c1aef7e0
"jetbrains:/idea/checkout/git" did not exist on "0c6ad747ddc10fc7f2d25737c837b44cd1c67833"
Commit
c1aef7e0
authored
May 02, 2019
by
misterbooo
Browse files
Remove Code
parent
5871d9af
Changes
146
Hide whitespace changes
Inline
Side-by-side
0283-Move-Zeroes/cpp-0283/main3.cpp
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/move-zeroes/description/
/// Author : liuyubobobo
/// Time : 2017-02-09
#include
<iostream>
#include
<vector>
using
namespace
std
;
// Time Complexity: O(n)
// Space Complexity: O(1)
class
Solution
{
public:
void
moveZeroes
(
vector
<
int
>&
nums
)
{
int
k
=
0
;
// keep nums[0...k) are all zero elements
for
(
int
i
=
0
;
i
<
nums
.
size
()
;
i
++
)
if
(
nums
[
i
])
swap
(
nums
[
k
++
]
,
nums
[
i
]);
}
};
void
printVec
(
const
vector
<
int
>&
vec
){
for
(
int
e
:
vec
)
cout
<<
e
<<
" "
;
cout
<<
endl
;
}
int
main
()
{
int
arr
[]
=
{
0
,
1
,
0
,
3
,
12
};
vector
<
int
>
vec
(
arr
,
arr
+
sizeof
(
arr
)
/
sizeof
(
int
));
Solution
().
moveZeroes
(
vec
);
printVec
(
vec
);
return
0
;
}
\ No newline at end of file
0283-Move-Zeroes/cpp-0283/main4.cpp
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/move-zeroes/description/
/// Author : liuyubobobo
/// Time : 2017-02-09
#include
<iostream>
#include
<vector>
using
namespace
std
;
// Time Complexity: O(n)
// Space Complexity: O(1)
class
Solution
{
public:
void
moveZeroes
(
vector
<
int
>&
nums
)
{
int
k
=
0
;
// keep nums[0...k) are all zero elements
for
(
int
i
=
0
;
i
<
nums
.
size
()
;
i
++
)
if
(
nums
[
i
])
// avoid self swapping
if
(
k
!=
i
)
swap
(
nums
[
k
++
],
nums
[
i
]);
else
k
++
;
}
};
void
printVec
(
const
vector
<
int
>&
vec
){
for
(
int
e
:
vec
)
cout
<<
e
<<
" "
;
cout
<<
endl
;
}
int
main
()
{
int
arr
[]
=
{
0
,
1
,
0
,
3
,
12
};
vector
<
int
>
vec
(
arr
,
arr
+
sizeof
(
arr
)
/
sizeof
(
int
));
Solution
().
moveZeroes
(
vec
);
printVec
(
vec
);
return
0
;
}
\ No newline at end of file
0283-Move-Zeroes/java-0283/src/Solution1.java
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/move-zeroes/description/
/// Author : liuyubobobo
/// Time : 2017-02-09
import
java.util.*
;
// Time Complexity: O(n)
// Space Complexity: O(n)
class
Solution1
{
public
void
moveZeroes
(
int
[]
nums
)
{
ArrayList
<
Integer
>
nonZeroElements
=
new
ArrayList
<
Integer
>();
// put all the non zero elements into a new vector
for
(
int
i
=
0
;
i
<
nums
.
length
;
i
++)
if
(
nums
[
i
]
!=
0
)
nonZeroElements
.
add
(
nums
[
i
]);
// make nums[0...nonZeroElements.size()) all non zero elements
for
(
int
i
=
0
;
i
<
nonZeroElements
.
size
();
i
++)
nums
[
i
]
=
nonZeroElements
.
get
(
i
);
// make nums[nonZeroElements.size()...nums.size()) all zero elements
for
(
int
i
=
nonZeroElements
.
size
();
i
<
nums
.
length
;
i
++)
nums
[
i
]
=
0
;
}
private
static
void
printArr
(
int
[]
arr
){
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
System
.
out
.
print
(
arr
[
i
]
+
" "
);
System
.
out
.
println
();
}
public
static
void
main
(
String
args
[]){
int
[]
arr
=
{
0
,
1
,
0
,
3
,
12
};
(
new
Solution1
()).
moveZeroes
(
arr
);
printArr
(
arr
);
}
}
\ No newline at end of file
0283-Move-Zeroes/java-0283/src/Solution2.java
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/move-zeroes/description/
/// Author : liuyubobobo
/// Time : 2017-02-09
import
java.util.*
;
// Time Complexity: O(n)
// Space Complexity: O(n)
class
Solution2
{
public
void
moveZeroes
(
int
[]
nums
)
{
int
k
=
0
;
// keep nums[0...k) are all zero elements
for
(
int
i
=
0
;
i
<
nums
.
length
;
i
++)
if
(
nums
[
i
]
!=
0
)
nums
[
k
++]
=
nums
[
i
];
// make the nums[k...end) zeros
for
(
int
i
=
k
;
i
<
nums
.
length
;
i
++)
nums
[
i
]
=
0
;
}
private
static
void
printArr
(
int
[]
arr
){
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
System
.
out
.
print
(
arr
[
i
]
+
" "
);
System
.
out
.
println
();
}
public
static
void
main
(
String
args
[]){
int
[]
arr
=
{
0
,
1
,
0
,
3
,
12
};
(
new
Solution2
()).
moveZeroes
(
arr
);
printArr
(
arr
);
}
}
\ No newline at end of file
0283-Move-Zeroes/java-0283/src/Solution3.java
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/move-zeroes/description/
/// Author : liuyubobobo
/// Time : 2017-02-09
import
java.util.*
;
// Time Complexity: O(n)
// Space Complexity: O(n)
class
Solution3
{
public
void
moveZeroes
(
int
[]
nums
)
{
int
k
=
0
;
// keep nums[0...k) are all zero elements
for
(
int
i
=
0
;
i
<
nums
.
length
;
i
++)
if
(
nums
[
i
]
!=
0
)
swap
(
nums
,
k
++,
i
);
}
private
void
swap
(
int
[]
nums
,
int
i
,
int
j
){
int
t
=
nums
[
i
];
nums
[
i
]
=
nums
[
j
];
nums
[
j
]
=
t
;
}
private
static
void
printArr
(
int
[]
arr
){
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
System
.
out
.
print
(
arr
[
i
]
+
" "
);
System
.
out
.
println
();
}
public
static
void
main
(
String
args
[]){
int
[]
arr
=
{
0
,
1
,
0
,
3
,
12
};
(
new
Solution3
()).
moveZeroes
(
arr
);
printArr
(
arr
);
}
}
\ No newline at end of file
0283-Move-Zeroes/java-0283/src/Solution4.java
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/move-zeroes/description/
/// Author : liuyubobobo
/// Time : 2017-02-09
import
java.util.*
;
// Time Complexity: O(n)
// Space Complexity: O(n)
class
Solution4
{
public
void
moveZeroes
(
int
[]
nums
)
{
int
k
=
0
;
// keep nums[0...k) are all zero elements
for
(
int
i
=
0
;
i
<
nums
.
length
;
i
++)
if
(
nums
[
i
]
!=
0
)
if
(
k
!=
i
)
swap
(
nums
,
k
++,
i
);
else
k
++;
}
private
void
swap
(
int
[]
nums
,
int
i
,
int
j
){
int
t
=
nums
[
i
];
nums
[
i
]
=
nums
[
j
];
nums
[
j
]
=
t
;
}
private
static
void
printArr
(
int
[]
arr
){
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
System
.
out
.
print
(
arr
[
i
]
+
" "
);
System
.
out
.
println
();
}
public
static
void
main
(
String
args
[]){
int
[]
arr
=
{
0
,
1
,
0
,
3
,
12
};
(
new
Solution4
()).
moveZeroes
(
arr
);
printArr
(
arr
);
}
}
\ No newline at end of file
0328-Odd-Even-Linked-List/cpp-0328/CMakeLists.txt
deleted
100755 → 0
View file @
5871d9af
cmake_minimum_required
(
VERSION 3.5
)
project
(
cpp_0328
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11"
)
set
(
SOURCE_FILES main2.cpp
)
add_executable
(
cpp_0328
${
SOURCE_FILES
}
)
\ No newline at end of file
0328-Odd-Even-Linked-List/cpp-0328/main.cpp
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/odd-even-linked-list/description/
/// Author : liuyubobobo
/// Time : 2018-10-01
#include
<iostream>
using
namespace
std
;
/// Definition for singly-linked list.
struct
ListNode
{
int
val
;
ListNode
*
next
;
ListNode
(
int
x
)
:
val
(
x
),
next
(
NULL
)
{}
};
/// Split the Linked List into two and then merge
/// Time Complexity: O(n)
/// Space Complexity: O(1)
class
Solution
{
public:
ListNode
*
oddEvenList
(
ListNode
*
head
)
{
if
(
head
==
NULL
||
head
->
next
==
NULL
||
head
->
next
->
next
==
NULL
)
return
head
;
ListNode
*
dummyHead1
=
new
ListNode
(
-
1
);
ListNode
*
dummyHead2
=
new
ListNode
(
-
1
);
ListNode
*
p1
=
dummyHead1
;
ListNode
*
p2
=
dummyHead2
;
ListNode
*
p
=
head
;
for
(
int
i
=
0
;
p
;
i
++
)
if
(
i
%
2
==
0
){
p1
->
next
=
p
;
p
=
p
->
next
;
p1
=
p1
->
next
;
p1
->
next
=
NULL
;
}
else
{
p2
->
next
=
p
;
p
=
p
->
next
;
p2
=
p2
->
next
;
p2
->
next
=
NULL
;
}
p1
->
next
=
dummyHead2
->
next
;
ListNode
*
ret
=
dummyHead1
->
next
;
delete
dummyHead1
;
delete
dummyHead2
;
return
ret
;
}
};
int
main
()
{
return
0
;
}
\ No newline at end of file
0328-Odd-Even-Linked-List/cpp-0328/main2.cpp
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/odd-even-linked-list/description/
/// Author : liuyubobobo
/// Time : 2018-10-01
#include
<iostream>
using
namespace
std
;
/// Definition for singly-linked list.
struct
ListNode
{
int
val
;
ListNode
*
next
;
ListNode
(
int
x
)
:
val
(
x
),
next
(
NULL
)
{}
};
/// Split the Linked List into two and then merge
/// Keep one in original Linked List
///
/// Time Complexity: O(n)
/// Space Complexity: O(1)
class
Solution
{
public:
ListNode
*
oddEvenList
(
ListNode
*
head
)
{
if
(
head
==
NULL
||
head
->
next
==
NULL
||
head
->
next
->
next
==
NULL
)
return
head
;
ListNode
*
dummyHead2
=
new
ListNode
(
-
1
);
ListNode
*
p2
=
dummyHead2
;
ListNode
*
p
=
head
;
while
(
p
->
next
){
p2
->
next
=
p
->
next
;
if
(
p
->
next
->
next
==
NULL
){
p
->
next
=
NULL
;
break
;
}
p
->
next
=
p
->
next
->
next
;
p
=
p
->
next
;
p2
=
p2
->
next
;
p2
->
next
=
NULL
;
}
p
->
next
=
dummyHead2
->
next
;
delete
dummyHead2
;
return
head
;
}
};
int
main
()
{
return
0
;
}
\ No newline at end of file
0344-Reverse-String/cpp-0344/CMakeLists.txt
deleted
100755 → 0
View file @
5871d9af
cmake_minimum_required
(
VERSION 3.5
)
project
(
cpp_0344
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11"
)
set
(
SOURCE_FILES main.cpp
)
add_executable
(
cpp_0344
${
SOURCE_FILES
}
)
\ No newline at end of file
0344-Reverse-String/cpp-0344/main.cpp
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/reverse-string/description/
/// Author : liuyubobobo
/// Time : 2018-06-04
#include
<iostream>
using
namespace
std
;
// 344. Reverse String
// https://leetcode.com/problems/reverse-string/description/
// Two Pointers
// 时间复杂度: O(n)
// 空间复杂度: O(1)
class
Solution
{
public:
string
reverseString
(
string
s
)
{
int
i
=
0
,
j
=
s
.
size
()
-
1
;
while
(
i
<
j
){
swap
(
s
[
i
],
s
[
j
]);
i
++
;
j
--
;
}
return
s
;
}
};
int
main
()
{
cout
<<
Solution
().
reverseString
(
"hello"
)
<<
endl
;
return
0
;
}
0349-Intersection-of-Two-Arrays/cpp-0349/CMakeLists.txt
deleted
100755 → 0
View file @
5871d9af
cmake_minimum_required
(
VERSION 3.5
)
project
(
cpp_0349
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11"
)
set
(
SOURCE_FILES main.cpp
)
add_executable
(
cpp_0349
${
SOURCE_FILES
}
)
\ No newline at end of file
0349-Intersection-of-Two-Arrays/cpp-0349/main.cpp
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/intersection-of-two-arrays/description/
/// Author : liuyubobobo
/// Time : 2017-07-12
#include
<iostream>
#include
<vector>
#include
<unordered_set>
using
namespace
std
;
/// Hash Set
/// Time complexity: O(len(nums1) + len(nums2))
/// Space Complexity: O(len(nums1))
class
Solution
{
public:
vector
<
int
>
intersection
(
vector
<
int
>&
nums1
,
vector
<
int
>&
nums2
)
{
unordered_set
<
int
>
record
(
nums1
.
begin
(),
nums1
.
end
());
unordered_set
<
int
>
resultSet
;
for
(
int
i
=
0
;
i
<
nums2
.
size
()
;
i
++
)
if
(
record
.
find
(
nums2
[
i
])
!=
record
.
end
()
)
resultSet
.
insert
(
nums2
[
i
]
);
return
vector
<
int
>
(
resultSet
.
begin
(),
resultSet
.
end
());
}
};
void
printVec
(
const
vector
<
int
>&
vec
){
for
(
int
e
:
vec
)
cout
<<
e
<<
" "
;
cout
<<
endl
;
}
int
main
()
{
int
nums1
[]
=
{
1
,
2
,
2
,
1
};
vector
<
int
>
vec1
(
nums1
,
nums1
+
sizeof
(
nums1
)
/
sizeof
(
int
));
int
nums2
[]
=
{
2
,
2
};
vector
<
int
>
vec2
(
nums2
,
nums2
+
sizeof
(
nums2
)
/
sizeof
(
int
));
printVec
(
Solution
().
intersection
(
vec1
,
vec2
));
return
0
;
}
\ No newline at end of file
0349-Intersection-of-Two-Arrays/java-0349/src/Solution.java
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/intersection-of-two-arrays/description/
/// Author : liuyubobobo
/// Time : 2017-07-12
import
java.util.HashSet
;
/// Hash Set
/// Time complexity: O(len(nums1) + len(nums2))
/// Space Complexity: O(len(nums1))
public
class
Solution
{
public
int
[]
intersection
(
int
[]
nums1
,
int
[]
nums2
)
{
HashSet
<
Integer
>
record
=
new
HashSet
<
Integer
>();
for
(
int
num:
nums1
)
record
.
add
(
num
);
HashSet
<
Integer
>
resultSet
=
new
HashSet
<
Integer
>();
for
(
int
num:
nums2
)
if
(
record
.
contains
(
num
))
resultSet
.
add
(
num
);
int
[]
res
=
new
int
[
resultSet
.
size
()];
int
index
=
0
;
for
(
Integer
num:
resultSet
)
res
[
index
++]
=
num
;
return
res
;
}
private
static
void
printArr
(
int
[]
arr
){
for
(
int
e:
arr
)
System
.
out
.
print
(
e
+
" "
);
System
.
out
.
println
();
}
public
static
void
main
(
String
[]
args
)
{
int
[]
nums1
=
{
1
,
2
,
2
,
1
};
int
[]
nums2
=
{
2
,
2
};
int
[]
res
=
(
new
Solution
()).
intersection
(
nums1
,
nums2
);
printArr
(
res
);
}
}
\ No newline at end of file
0350-Intersection-of-Two-Arrays-II/cpp-0350/CMakeLists.txt
deleted
100755 → 0
View file @
5871d9af
cmake_minimum_required
(
VERSION 3.5
)
project
(
cpp_0350
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11"
)
set
(
SOURCE_FILES main.cpp
)
add_executable
(
cpp_0350
${
SOURCE_FILES
}
)
\ No newline at end of file
0350-Intersection-of-Two-Arrays-II/cpp-0350/main.cpp
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/intersection-of-two-arrays-ii/description/
/// Author : liuyubobobo
/// Time : 2017-11-14
#include
<iostream>
#include
<vector>
#include
<unordered_map>
using
namespace
std
;
/// Using Hash Map
/// Time Complexity: O(len(nums1) + len(nums2))
/// Space Complexity: O(len(nums1))
class
Solution
{
public:
vector
<
int
>
intersect
(
vector
<
int
>&
nums1
,
vector
<
int
>&
nums2
)
{
unordered_map
<
int
,
int
>
record
;
for
(
int
i
=
0
;
i
<
nums1
.
size
()
;
i
++
)
record
[
nums1
[
i
]]
+=
1
;
vector
<
int
>
resultVector
;
for
(
int
i
=
0
;
i
<
nums2
.
size
()
;
i
++
)
if
(
record
[
nums2
[
i
]]
>
0
){
resultVector
.
push_back
(
nums2
[
i
]);
record
[
nums2
[
i
]]
--
;
}
return
resultVector
;
}
};
void
printVec
(
const
vector
<
int
>&
vec
){
for
(
int
e
:
vec
)
cout
<<
e
<<
" "
;
cout
<<
endl
;
}
int
main
()
{
int
nums1
[]
=
{
1
,
2
,
2
,
1
};
vector
<
int
>
vec1
(
nums1
,
nums1
+
sizeof
(
nums1
)
/
sizeof
(
int
));
int
nums2
[]
=
{
2
,
2
};
vector
<
int
>
vec2
(
nums2
,
nums2
+
sizeof
(
nums2
)
/
sizeof
(
int
));
printVec
(
Solution
().
intersect
(
vec1
,
vec2
));
return
0
;
}
\ No newline at end of file
0350-Intersection-of-Two-Arrays-II/cpp-0350/main2.cpp
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/intersection-of-two-arrays-ii/description/
/// Author : liuyubobobo
/// Time : 2017-11-14
#include
<iostream>
#include
<vector>
#include
<set>
using
namespace
std
;
/// Using Hash Map
/// Time Complexity: O(len(nums1) + len(nums2)*log(len(nums1)))
/// Space Complexity: O(len(nums1))
class
Solution
{
public:
vector
<
int
>
intersect
(
vector
<
int
>&
nums1
,
vector
<
int
>&
nums2
)
{
multiset
<
int
>
record
;
for
(
int
num
:
nums1
)
record
.
insert
(
num
);
multiset
<
int
>
result
;
for
(
int
num
:
nums2
){
multiset
<
int
>::
iterator
iter
=
record
.
find
(
num
);
if
(
iter
!=
record
.
end
()){
result
.
insert
(
num
);
record
.
erase
(
iter
);
}
}
return
vector
<
int
>
(
result
.
begin
(),
result
.
end
());
}
};
int
main
()
{
int
nums1
[]
=
{
1
,
2
,
2
,
1
};
vector
<
int
>
vec1
(
nums1
,
nums1
+
sizeof
(
nums1
)
/
sizeof
(
int
));
int
nums2
[]
=
{
2
,
2
};
vector
<
int
>
vec2
(
nums2
,
nums2
+
sizeof
(
nums2
)
/
sizeof
(
int
));
printVec
(
Solution
().
intersect
(
vec1
,
vec2
));
return
0
;
}
\ No newline at end of file
0350-Intersection-of-Two-Arrays-II/java-0350/src/Solution.java
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/intersection-of-two-arrays-ii/description/
/// Author : liuyubobobo
/// Time : 2017-11-14
import
java.util.HashMap
;
import
java.util.ArrayList
;
/// Using Hash Map
/// Time Complexity: O(len(nums1) + len(nums2)*log(len(nums1)))
/// Space Complexity: O(len(nums1))
public
class
Solution
{
public
int
[]
intersect
(
int
[]
nums1
,
int
[]
nums2
)
{
HashMap
<
Integer
,
Integer
>
record
=
new
HashMap
<
Integer
,
Integer
>();
for
(
int
num:
nums1
)
if
(!
record
.
containsKey
(
num
))
record
.
put
(
num
,
1
);
else
record
.
put
(
num
,
record
.
get
(
num
)
+
1
);
ArrayList
<
Integer
>
result
=
new
ArrayList
<
Integer
>();
for
(
int
num:
nums2
)
if
(
record
.
containsKey
(
num
)
&&
record
.
get
(
num
)
>
0
){
result
.
add
(
num
);
record
.
put
(
num
,
record
.
get
(
num
)
-
1
);
}
int
[]
ret
=
new
int
[
result
.
size
()];
int
index
=
0
;
for
(
Integer
num:
result
)
ret
[
index
++]
=
num
;
return
ret
;
}
private
static
void
printArr
(
int
[]
arr
){
for
(
int
e:
arr
)
System
.
out
.
print
(
e
+
" "
);
System
.
out
.
println
();
}
public
static
void
main
(
String
[]
args
)
{
int
[]
nums1
=
{
1
,
2
,
2
,
1
};
int
[]
nums2
=
{
2
,
2
};
int
[]
res
=
(
new
Solution
()).
intersect
(
nums1
,
nums2
);
printArr
(
res
);
}
}
0447-Number-of-Boomerangs/cpp-0447/CMakeLists.txt
deleted
100755 → 0
View file @
5871d9af
cmake_minimum_required
(
VERSION 3.5
)
project
(
cpp_0447
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11"
)
set
(
SOURCE_FILES main.cpp
)
add_executable
(
cpp_0447
${
SOURCE_FILES
}
)
\ No newline at end of file
0447-Number-of-Boomerangs/cpp-0447/main.cpp
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/number-of-boomerangs/description/
/// Author : liuyubobobo
/// Time : 2017-11-15
#include
<iostream>
#include
<vector>
#include
<unordered_map>
#include
<cassert>
#include
<stdexcept>
using
namespace
std
;
/// Using Hash Map
/// Time Complexity: O(n^2)
/// Space Complexity: O(n)
class
Solution
{
public:
int
numberOfBoomerangs
(
vector
<
pair
<
int
,
int
>>&
points
)
{
int
res
=
0
;
for
(
int
i
=
0
;
i
<
points
.
size
()
;
i
++
){
// record中存储 点i 到所有其他点的距离出现的频次
unordered_map
<
int
,
int
>
record
;
for
(
int
j
=
0
;
j
<
points
.
size
()
;
j
++
)
if
(
j
!=
i
)
// 计算距离时不进行开根运算, 以保证精度
record
[
dis
(
points
[
i
],
points
[
j
])]
+=
1
;
for
(
unordered_map
<
int
,
int
>::
iterator
iter
=
record
.
begin
()
;
iter
!=
record
.
end
()
;
iter
++
)
res
+=
(
iter
->
second
)
*
(
iter
->
second
-
1
);
}
return
res
;
}
private:
int
dis
(
const
pair
<
int
,
int
>
&
pa
,
const
pair
<
int
,
int
>
&
pb
){
return
(
pa
.
first
-
pb
.
first
)
*
(
pa
.
first
-
pb
.
first
)
+
(
pa
.
second
-
pb
.
second
)
*
(
pa
.
second
-
pb
.
second
);
}
};
int
main
()
{
vector
<
pair
<
int
,
int
>>
vec
;
vec
.
push_back
(
make_pair
(
0
,
0
));
vec
.
push_back
(
make_pair
(
1
,
0
));
vec
.
push_back
(
make_pair
(
2
,
0
));
cout
<<
Solution
().
numberOfBoomerangs
(
vec
)
<<
endl
;
return
0
;
}
\ No newline at end of file
Prev
1
…
3
4
5
6
7
8
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment