Labels

algorithms (22) Design Patterns (20) java (19) linux (14) Snippet (13) service mix (6) soa (4)

Cloudizza

Cloudizza

Anagram Detector

/** 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;
}
}

}

15 comments:

  1. 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

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. A 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

    ReplyDelete
  4. Please 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.
    Lie Detector Test

    ReplyDelete
  5. I really like whenever you write. This kind of work is really praiseable thanks for sharing...http://www.liedetectortest.us

    ReplyDelete
  6. I 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

    ReplyDelete
  7. Thanks for sharing! Had you ever use metal detector? I looking for best metal detector but i donk't know wich to choose...

    ReplyDelete
  8. I 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

    ReplyDelete
  9. Great Article is there any way we can reach to maximum depth of detector for best performance.

    ReplyDelete
  10. A 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

    ReplyDelete
  11. Thanks for the blog loaded with so many information.
    دانلود فیلم دشمن زن

    ReplyDelete
  12. Thanks for this informative blog it help me lot with metal detector https://golddetectors.pk/

    ReplyDelete
  13. Thanks for this informative blog it help me lot with metal detector https://golddetectors.pk/

    ReplyDelete
  14. Now 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

    ReplyDelete

Search 24 Bytes