Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<map>
- bool check(std::vector<int> a,std::vector<int> b)
- {
- if(a.size()!=b.size())return false;
- std::map<int,int> fd;//using hashing here will decrease time complexity while increasing place required
- for(int i=0;i<a.size();++i)
- {
- fd[a[i]]++;
- fd[b[i]]--;
- }
- for(auto& x:fd)
- if(x.second!=0)return false;
- return true;
- }
- int main()
- {
- std::cout<<check({1,2,3,4,5},{5,4,3,2,1});
- }
Advertisement
Add Comment
Please, Sign In to add comment