We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9a67ec3 commit cf8bc86Copy full SHA for cf8bc86
C++/image-overlap.cpp
@@ -0,0 +1,26 @@
1
+// Time: O(n^4)
2
+// Space: O(n^2)
3
+
4
+class Solution {
5
+public:
6
+ int largestOverlap(vector<vector<int>>& A, vector<vector<int>>& B) {
7
+ vector<int> count(pow(2 * A.size() - 1, 2));
8
+ for (int i = 0; i < A.size(); ++i) {
9
+ for (int j = 0; j < A[i].size(); ++j) {
10
+ if (!A[i][j]) {
11
+ continue;
12
+ }
13
+ for (int m = 0; m < B.size(); ++m) {
14
+ for (int n = 0; n < B[m].size(); ++n) {
15
+ if (!B[m][n]) {
16
17
18
+ ++count[(A.size() - 1 + i - m) * (2 * A.size() - 1) +
19
+ A.size() - 1 + j - n];
20
21
22
23
24
+ return *max_element(count.cbegin(), count.cend());
25
26
+};
0 commit comments