mramine364

Valid Anagram

Aug 26th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. bool validAnagram(string s1,string s2)
  7. {
  8.     if( s1.size()!=s2.size() )
  9.         return false;
  10.     int i,j;
  11.     for(i=0;i<s1.size();i++){
  12.         for(j=0;j<s2.size();j++){
  13.             if( s1[i]==s2[j] )
  14.                 break;
  15.         }
  16.         if( j==s2.size() ) break;
  17.     }
  18.     return i==s1.size();
  19. }
  20. int main()
  21. {
  22.    cout << validAnagram("race", "crre") << endl;
  23.    
  24.    return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment