Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

What would be the best logic to check all the letters in a given string.

If all the 26 letters are available in the provided string, I want to check that and perform so ops. eg. Pack my box with five dozen liquor jugs.

  1. Would using a Hash be useful?
  2. Or using a bit map? or any other way?

BTW my code would be in Java.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
320 views
Welcome To Ask or Share your Answers For Others

1 Answer

Using a BitMap, I'm assuming you meant case insenstive.

Update: Solution by Thomas is more efficient, than the following. :) Use that one.

    //
    String test  = "abcdefeghjiklmnopqrstuvwxyz";

    BitSet alpha = new BitSet(26);
    for(char ch : test.toUpperCase().toCharArray())
        if(Character.isLetter(ch))
            alpha.set(ch - 65);

    System.out.println(alpha.cardinality() == 26);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...