Checking if two strings are permutations of each other

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

How to determine if two strings are permutations of each other

30条回答
  •  甜味超标
    2020-12-05 09:00

    The obligatory Guava one-liner:

    boolean isAnagram(String s1, String s2) {
        return ImmutableMultiset.copyOf(Chars.asList(s1.toCharArray())).equals(ImmutableMultiset.copyOf(Chars.asList(s2.toCharArray())));
    }
    

    (Just for fun. I don't recommend submitting this for your assignment.)

提交回复
热议问题