我有一个返回的方法Set<Set<String>>.在我的测试中,我试图Set使用contains()方法检查预期的s是否存在.
例如. input = "cat", "dog", "god"
output = [[cat], [dog, god]]
现在,如果我这样做output.contains(new HashSet<>(Arrays.asList("cat")))会返回true.
但如果我这样做output.contains(new HashSet<>(Arrays.asList("dog", "god")))就会回来false.
根据我的理解,它应该true在两种情况下都返回.
我在这里错过了什么?
public class AnagramGroups {
public Set<Set<String>> group(Set<String> words) {
Set<Set<String>> groups = new HashSet<>();
for(String word: words) {
findAndAdd(word, groups);
}
return groups;
}
private void findAndAdd(String word, Set<Set<String>> groups) {
for(Set<String> group: groups) {
boolean found = false;
for(String str: group) {
if(isAnagram(str, word)) …Run Code Online (Sandbox Code Playgroud)