Back to course home
0% completed
Vote For New Content
Insufficient testcases
Ejike Nwude
Nov 30, 2023
Your testcases allow the following solution to pass when it should fail. For instance the following are not anagrams {add, ada} but since a Set does not account for the frequency, it passes them as anagrams:
import java.util.Arrays; import java.util.HashSet; import java.util.Set; class Solution { public boolean isAnagram(String s, String t) { if (s.length() != t.length()) { return false; } Set<Character> characters = new HashSet<>(); for (char c : s.toCharArray()) { characters.add(c); } for (char character : t.toCharArray()) { if (!characters.contains(character)) { return false; } } return true; } }
1
0
Comments
Comments
John Snow2 years ago
Sure for the poor test cases, I have a simple code could pass this exam.
import java.util.HashMap; class Solution { public boolean isAnagram(String s, String t) { // TODO: Write your code here if (t.length() != s.length()) { return false; ...