-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp
More file actions
28 lines (25 loc) · 704 Bytes
/
cpp
File metadata and controls
28 lines (25 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution {
public:
bool canBeEqual(vector<int>& target, vector<int>& arr) {
// sort(target.begin(), target.end());
// sort(arr.begin(), arr.end());
// for(int i = 0; i < target.size(); i++){
// if(target[i] != arr[i]){
// return false;
// }
// }
// return true;
//bucket
vector<int> bucket(1001);
for (int i=0;i<target.size();i++)
bucket[target[i]]++;
for (int i=0;i<arr.size();i++) {
bucket[arr[i]]--;
}
for(int j=0;j<bucket.size();j++){
if(bucket[j]!=0)
return false;
}
return true;
}
};