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
Commit
c1aef7e0
authored
May 02, 2019
by
misterbooo
Browse files
Remove Code
parent
5871d9af
Changes
146
Hide whitespace changes
Inline
Side-by-side
0447-Number-of-Boomerangs/java-0447/src/Solution.java
deleted
100755 → 0
View file @
5871d9af
/// Source : https://leetcode.com/problems/number-of-boomerangs/description/
/// Author : liuyubobobo
/// Time : 2017-11-15
import
java.util.HashMap
;
/// Using Hash Map
/// Time Complexity: O(n^2)
/// Space Complexity: O(n)
public
class
Solution
{
public
int
numberOfBoomerangs
(
int
[][]
points
)
{
int
res
=
0
;
for
(
int
i
=
0
;
i
<
points
.
length
;
i
++
){
// record中存储 点i 到所有其他点的距离出现的频次
HashMap
<
Integer
,
Integer
>
record
=
new
HashMap
<
Integer
,
Integer
>();
for
(
int
j
=
0
;
j
<
points
.
length
;
j
++)
if
(
j
!=
i
){
// 计算距离时不进行开根运算, 以保证精度
int
dis
=
dis
(
points
[
i
],
points
[
j
]);
if
(
record
.
containsKey
(
dis
))
record
.
put
(
dis
,
record
.
get
(
dis
)
+
1
);
else
record
.
put
(
dis
,
1
);
}
for
(
Integer
dis:
record
.
keySet
())
res
+=
record
.
get
(
dis
)
*
(
record
.
get
(
dis
)
-
1
);
}
return
res
;
}
private
int
dis
(
int
[]
pa
,
int
pb
[]){
return
(
pa
[
0
]
-
pb
[
0
])
*
(
pa
[
0
]
-
pb
[
0
])
+
(
pa
[
1
]
-
pb
[
1
])
*
(
pa
[
1
]
-
pb
[
1
]);
}
public
static
void
main
(
String
[]
args
)
{
int
[][]
points
=
{{
0
,
0
},
{
1
,
0
},
{
2
,
0
}};
System
.
out
.
println
((
new
Solution
()).
numberOfBoomerangs
(
points
));
}
}
0454-4Sum-II/cpp-0454/CMakeLists.txt
deleted
100755 → 0
View file @
5871d9af
cmake_minimum_required
(
VERSION 3.5
)
project
(
cpp_0454
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11"
)
set
(
SOURCE_FILES main.cpp
)
add_executable
(
cpp_0454
${
SOURCE_FILES
}
)
\ No newline at end of file
0454-4Sum-II/cpp-0454/main.cpp
deleted
100755 → 0
View file @
5871d9af
/// https://leetcode.com/problems/4sum-ii/description/
/// Author : liuyubobobo
/// Time : 2017-11-15
#include
<iostream>
#include
<vector>
#include
<unordered_map>
#include
<cassert>
using
namespace
std
;
/// Using Hash Map
/// Time Complexity: O(n^2)
/// Space Complexity: O(n^2)
class
Solution
{
public:
int
fourSumCount
(
vector
<
int
>&
A
,
vector
<
int
>&
B
,
vector
<
int
>&
C
,
vector
<
int
>&
D
)
{
unordered_map
<
int
,
int
>
hashtable
;
for
(
int
i
=
0
;
i
<
C
.
size
()
;
i
++
)
for
(
int
j
=
0
;
j
<
D
.
size
()
;
j
++
)
hashtable
[
C
[
i
]
+
D
[
j
]]
+=
1
;
int
res
=
0
;
for
(
int
i
=
0
;
i
<
A
.
size
()
;
i
++
)
for
(
int
j
=
0
;
j
<
B
.
size
()
;
j
++
)
if
(
hashtable
.
find
(
-
A
[
i
]
-
B
[
j
])
!=
hashtable
.
end
())
res
+=
hashtable
[
-
A
[
i
]
-
B
[
j
]];
return
res
;
}
};
int
main
()
{
int
a
[]
=
{
1
,
2
};
int
b
[]
=
{
-
2
,
-
1
};
int
c
[]
=
{
-
1
,
2
};
int
d
[]
=
{
0
,
2
};
vector
<
int
>
a_vec
=
vector
<
int
>
(
a
,
a
+
sizeof
(
a
)
/
sizeof
(
int
));
vector
<
int
>
b_vec
=
vector
<
int
>
(
b
,
b
+
sizeof
(
b
)
/
sizeof
(
int
));
vector
<
int
>
c_vec
=
vector
<
int
>
(
c
,
c
+
sizeof
(
c
)
/
sizeof
(
int
));
vector
<
int
>
d_vec
=
vector
<
int
>
(
d
,
d
+
sizeof
(
d
)
/
sizeof
(
int
));
cout
<<
Solution
().
fourSumCount
(
a_vec
,
b_vec
,
c_vec
,
d_vec
)
<<
endl
;
return
0
;
}
0454-4Sum-II/cpp-0454/main2.cpp
deleted
100755 → 0
View file @
5871d9af
/// https://leetcode.com/problems/4sum-ii/description/
/// Author : liuyubobobo
/// Time : 2017-11-15
#include
<iostream>
#include
<vector>
#include
<unordered_map>
#include
<cassert>
#include
<stdexcept>
using
namespace
std
;
/// Another Way to use Hash Map
/// Time Complexity: O(n^2)
/// Space Complexity: O(n^2)
class
Solution
{
public:
int
fourSumCount
(
vector
<
int
>&
A
,
vector
<
int
>&
B
,
vector
<
int
>&
C
,
vector
<
int
>&
D
)
{
unordered_map
<
int
,
int
>
hashtable1
;
unordered_map
<
int
,
int
>
hashtable2
;
for
(
int
i
=
0
;
i
<
A
.
size
()
;
i
++
)
for
(
int
j
=
0
;
j
<
B
.
size
()
;
j
++
)
hashtable1
[
A
[
i
]
+
B
[
j
]]
+=
1
;
for
(
int
i
=
0
;
i
<
C
.
size
()
;
i
++
)
for
(
int
j
=
0
;
j
<
D
.
size
()
;
j
++
)
hashtable2
[
C
[
i
]
+
D
[
j
]]
+=
1
;
int
res
=
0
;
for
(
unordered_map
<
int
,
int
>::
iterator
iter
=
hashtable1
.
begin
()
;
iter
!=
hashtable1
.
end
()
;
iter
++
)
if
(
hashtable2
.
find
(
-
(
iter
->
first
))
!=
hashtable2
.
end
())
res
+=
iter
->
second
*
hashtable2
[
-
(
iter
->
first
)];
return
res
;
}
};
int
main
()
{
int
a
[]
=
{
1
,
2
};
int
b
[]
=
{
-
2
,
-
1
};
int
c
[]
=
{
-
1
,
2
};
int
d
[]
=
{
0
,
2
};
vector
<
int
>
a_vec
=
vector
<
int
>
(
a
,
a
+
sizeof
(
a
)
/
sizeof
(
int
));
vector
<
int
>
b_vec
=
vector
<
int
>
(
b
,
b
+
sizeof
(
b
)
/
sizeof
(
int
));
vector
<
int
>
c_vec
=
vector
<
int
>
(
c
,
c
+
sizeof
(
c
)
/
sizeof
(
int
));
vector
<
int
>
d_vec
=
vector
<
int
>
(
d
,
d
+
sizeof
(
d
)
/
sizeof
(
int
));
cout
<<
Solution
().
fourSumCount
(
a_vec
,
b_vec
,
c_vec
,
d_vec
)
<<
endl
;
return
0
;
}
0454-4Sum-II/java-0454/src/Solution1.java
deleted
100755 → 0
View file @
5871d9af
/// https://leetcode.com/problems/4sum-ii/description/
/// Author : liuyubobobo
/// Time : 2017-11-15
import
java.util.HashMap
;
/// Using Hash Map
/// Time Complexity: O(n^2)
/// Space Complexity: O(n^2)
public
class
Solution1
{
public
int
fourSumCount
(
int
[]
A
,
int
[]
B
,
int
[]
C
,
int
[]
D
)
{
if
(
A
==
null
||
B
==
null
||
C
==
null
||
D
==
null
)
throw
new
IllegalArgumentException
(
"Illegal argument"
);
HashMap
<
Integer
,
Integer
>
map
=
new
HashMap
<
Integer
,
Integer
>();
for
(
int
i
=
0
;
i
<
C
.
length
;
i
++)
for
(
int
j
=
0
;
j
<
D
.
length
;
j
++){
int
sum
=
C
[
i
]
+
D
[
j
];
if
(
map
.
containsKey
(
sum
))
map
.
put
(
sum
,
map
.
get
(
sum
)
+
1
);
else
map
.
put
(
sum
,
1
);
}
int
res
=
0
;
for
(
int
i
=
0
;
i
<
A
.
length
;
i
++)
for
(
int
j
=
0
;
j
<
B
.
length
;
j
++)
if
(
map
.
containsKey
(-
A
[
i
]-
B
[
j
]))
res
+=
map
.
get
(-
A
[
i
]-
B
[
j
]);
return
res
;
}
public
static
void
main
(
String
[]
args
)
{
int
[]
a
=
{
1
,
2
};
int
[]
b
=
{-
2
,
-
1
};
int
[]
c
=
{-
1
,
2
};
int
[]
d
=
{
0
,
2
};
System
.
out
.
println
((
new
Solution1
()).
fourSumCount
(
a
,
b
,
c
,
d
));
}
}
0454-4Sum-II/java-0454/src/Solution2.java
deleted
100755 → 0
View file @
5871d9af
/// https://leetcode.com/problems/4sum-ii/description/
/// Author : liuyubobobo
/// Time : 2017-11-15
import
java.util.HashMap
;
/// Another Way to use Hash Map
/// Time Complexity: O(n^2)
/// Space Complexity: O(n^2)
public
class
Solution2
{
public
int
fourSumCount
(
int
[]
A
,
int
[]
B
,
int
[]
C
,
int
[]
D
)
{
if
(
A
==
null
||
B
==
null
||
C
==
null
||
D
==
null
)
throw
new
IllegalArgumentException
(
"Illegal argument"
);
HashMap
<
Integer
,
Integer
>
mapAB
=
new
HashMap
<
Integer
,
Integer
>();
for
(
int
i
=
0
;
i
<
A
.
length
;
i
++)
for
(
int
j
=
0
;
j
<
B
.
length
;
j
++){
int
sum
=
A
[
i
]
+
B
[
j
];
if
(
mapAB
.
containsKey
(
sum
))
mapAB
.
put
(
sum
,
mapAB
.
get
(
sum
)
+
1
);
else
mapAB
.
put
(
sum
,
1
);
}
HashMap
<
Integer
,
Integer
>
mapCD
=
new
HashMap
<
Integer
,
Integer
>();
for
(
int
i
=
0
;
i
<
C
.
length
;
i
++)
for
(
int
j
=
0
;
j
<
D
.
length
;
j
++){
int
sum
=
C
[
i
]
+
D
[
j
];
if
(
mapCD
.
containsKey
(
sum
))
mapCD
.
put
(
sum
,
mapCD
.
get
(
sum
)
+
1
);
else
mapCD
.
put
(
sum
,
1
);
}
int
res
=
0
;
for
(
Integer
sumab:
mapAB
.
keySet
()){
if
(
mapCD
.
containsKey
(-
sumab
))
res
+=
mapAB
.
get
(
sumab
)
*
mapCD
.
get
(-
sumab
);
}
return
res
;
}
public
static
void
main
(
String
[]
args
)
{
int
[]
a
=
{
1
,
2
};
int
[]
b
=
{-
2
,
-
1
};
int
[]
c
=
{-
1
,
2
};
int
[]
d
=
{
0
,
2
};
System
.
out
.
println
((
new
Solution2
()).
fourSumCount
(
a
,
b
,
c
,
d
));
}
}
Prev
1
…
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