finding if two words are anagrams of each other

后端 未结 22 1220
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 14:51

I am looking for a method to find if two strings are anagrams of one another.

Ex: string1 - abcde
string2 - abced
Ans = true
Ex: string1 - abcde
string2 - ab         


        
22条回答
  •  無奈伤痛
    2020-11-27 15:31

    How about Xor'ing both the strings??? This will definitely be of O(n)

    char* arr1="ab cde";
    int n1=strlen(arr1);
    char* arr2="edcb a";
    int n2=strlen(arr2);
    // to check for anagram;
    int c=0;
    int i=0, j=0;   
    if(n1!=n2) 
      printf("\nNot anagram");
    else {
       while(i

    }

提交回复
热议问题