检查字符串有字母表中的所有字母字母表、字符串、字母

2023-09-11 05:31:52 作者:你和她的葬礼我定盛装出席

什么是检查所有的字母给定的字符串中最好的逻辑。

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

如果所有26个字母都在提供的字符串可用,我要检查并执行这样欢声笑语。例如。我的包箱五打酒水罐。

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.

会使用散列是有用的? 或使用位图?或任何其他方式?

顺便说一句我的code将在Java中。

BTW my code would be in Java.

推荐答案

尚未完全优化的:

public static void main(String... a) {
    String s = "Pack my box with five dozen liquor jugs.";
    int i=0;
    for(char c : s.toCharArray()) {
        int x = Character.toUpperCase(c);
        if (x >= 'A' && x <= 'Z') {
            i |= 1 << (x - 'A');
        }
    }
    if (i == (i | ((1 << (1 + 'Z' - 'A')) - 1))) {
        System.out.println("ok");
    }
}