Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update _693.java#42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fishercoder1534 merged 2 commits intofishercoder1534:masterfromjianguda:patch-5
Mar 12, 2019
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletionssrc/main/java/com/fishercoder/solutions/_693.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,13 +31,20 @@
*/

public class _693 {
public boolean hasAlternatingBits(int n) {
String binaryStr = Integer.toBinaryString(n);
for (int i = 1; i < binaryStr.length(); i++) {
if (binaryStr.charAt(i - 1) == binaryStr.charAt(i)) {
return false;
public static class Solution1 {
public boolean hasAlternatingBits(int n) {
String binaryStr = Integer.toBinaryString(n);
for (int i = 1; i < binaryStr.length(); i++) {
if (binaryStr.charAt(i - 1) == binaryStr.charAt(i)) {
return false;
}
}
return true;
}
}
public static class Solution2 {
public boolean hasAlternatingBits_oneline(int n) {
return Integer.bitCount(((n >> 1) ^ n) + 1) == 1;
}
return true;
}
}

[8]ページ先頭

©2009-2025 Movatter.jp