/** Checks if two words are anagrams or not
* @param firstWord
* @param secondWord
*/
public static boolean areAnagram(String firstWord, String secondWord) {
int numberOfUnique = 0;
int processed = 0;
if (firstWord.length() != secondWord.length()) {
return false;
}
int[] chars = new int[256];
for (int i = 0; i < firstWord.length(); i++) {
if (chars[firstWord.charAt(i)] == 0) {
numberOfUnique++;
}
chars[firstWord.charAt(i)]++;
}
for (int i = 0; i < secondWord.length(); i++) {
// this char is not there so false
if (chars[secondWord.charAt(i)] == 0)
return false;
chars[secondWord.charAt(i)]--;
if (chars[secondWord.charAt(i)] == 0) {
processed++;
if (numberOfUnique == processed) {
System.out.println(processed);
return secondWord.length() == processed + 1;
}
}
}
Labels
Anagram Detector
Subscribe to:
Post Comments (Atom)
And here's the prototype that I knocked up in my workshop near Okehampton and found its way to Slapton via MozSpace London.Radar Detector Reviews
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteA metal detector finds the treasures that society has forgotten about or counted as lost. It can also find weapons that may have been buried deep in the ground.http://www.liedetector.uk
ReplyDeletePlease realize that I don't mean to recommend that each and every salon is doing this. But you have to be cautious in this matter. You can head to a tanning salon without the fear of being captured in the frame, if you truly play a little smart game.
ReplyDeleteLie Detector Test
I really like whenever you write. This kind of work is really praiseable thanks for sharing...http://www.liedetectortest.us
ReplyDeleteI recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often. www.liedetectortest.com
ReplyDeleteThanks for sharing! Had you ever use metal detector? I looking for best metal detector but i donk't know wich to choose...
ReplyDeleteI think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. Lie Detector Test
ReplyDeleteGreat Article is there any way we can reach to maximum depth of detector for best performance.
ReplyDeleteA metal detector finds the treasures that society has forgotten about or counted as lost. It can also find weapons that may have been buried deep in the ground
ReplyDeleteThanks for the blog loaded with so many information.
ReplyDeleteدانلود فیلم دشمن زن
Thanks for this informative blog it help me lot with metal detector https://golddetectors.pk/
ReplyDeleteThanks for this informative blog it help me lot with metal detector https://golddetectors.pk/
ReplyDeleteدانلود فیلم مطرب با لینک مستقیم
ReplyDeleteNow that you know what an anagram is, you are ready to dive into the fun world of solving anagrams. There are many anagram sites online, and most newsstand puzzle magazines also contain a good selection of anagram puzzles. https://wordigg.com/scrabble-word-finder
ReplyDeletegreat post
ReplyDeletevery helpful code. it really helped me in my project of gold detector in karachi
ReplyDelete