cc150 1.2 Check Permutation(排列)

来源:互联网 发布:中国依赖进口数据 编辑:程序博客网 时间:2024/06/06 18:19
1.2 Check Permutation(排列):   Given 2 strings, write a method to decide if one is a permutation of the other
待确认问题:
1 是否大小写敏感(case sensitive)?

2 空格是否可以忽略?


思路:

1  排序

2 判断是否相等


C#代码:O(NLOGN)

 public static bool Permutation(string str1,string str2)        {            if (str1 == string.Empty && str2 == string.Empty)                return true;            if (str1 == null || str2 == null)                return false;            char[] str1Arr = str1.Trim().ToCharArray();            char[] str2Arr = str2.Trim().ToCharArray();            Array.Sort(str1Arr);            Array.Sort(str2Arr);            return str1Arr.Equals(str2Arr);        }



0 0