Skip to content

Commit 96430ef

Browse files
authored
Create make-two-arrays-equal-by-reversing-sub-arrays.cpp
1 parent 06c29a5 commit 96430ef

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Time: O(n)
2+
// Space: O(n)
3+
4+
class Solution {
5+
public:
6+
bool canBeEqual(vector<int>& target, vector<int>& arr) {
7+
return counter(target) == counter(arr);
8+
}
9+
10+
private:
11+
unordered_map<int, int> counter(const vector<int>& arr) {
12+
unordered_map<int, int> count;
13+
for (const auto& x : arr) {
14+
++count[x];
15+
}
16+
return count;
17+
}
18+
};

0 commit comments

Comments
 (0)