gpt4 book ai didi

java - java新手——在实际使用中理解位操作

转载 作者:太空狗 更新时间:2023-10-29 16:37:04 25 4
gpt4 key购买 nike

<分区>

//determines if string contains unique characters

public static boolean isUniqueChars(String str) {
int checker = 0;
for (int i = 0; i < str.length(); ++i) {
int val = str.charAt(i) - 'a';
if ((checker & (1 << val)) > 0) <--- right here
return false;
checker |= (1 << val);
}
return true;
}

我所理解的是 << 向二进制数添加了额外的零,从而增加了值。例如:2<< 3 = 10 + 000 = 10000//二进制为 16。所以我的问题是,这在这里有什么用?这如何帮助我们找到独特的字符

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com