Checking if two strings are permutations of each other

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

How to determine if two strings are permutations of each other

30条回答
  •  被撕碎了的回忆
    2020-12-05 08:58

    I did this, and it works well and quickly:

    public static boolean isPermutation(String str1, String str2)
    {
        char[] x = str1.toCharArray();
        char[] y = str2.toCharArray();
        Arrays.sort(x);
        Arrays.sort(y);
        if(Arrays.equals(x, y))
            return true;
        return false;
    }
    

提交回复
热议问题