Checking if two strings are permutations of each other

前端 未结 30 1005
感情败类
感情败类 2020-12-05 08:19

How to determine if two strings are permutations of each other

30条回答
  •  离开以前
    2020-12-05 08:51

    I did it using C#

    bool Arepermutations(string string1, string string2)
            {
                char[] str1 = string1.ToCharArray();
                char[] str2 = string2.ToCharArray();
                if (str1.Length !=str2.Length)
                  return false; 
                Array.Sort(str1); 
                Array.Sort(str2);
                if (str1.Where((t, i) => t!= str2[i]).Any())
                {
                    return false;
                }
    
                return true; 
    
            }
    

提交回复
热议问题