MCPcopy Create free account
hub / github.com/careercup/ctci / hasValidNext

Method hasValidNext

java/Chapter 5/Question5_3/Question.java:20–37  ·  view source on GitHub ↗
(int i)

Source from the content-addressed store, hash-verified

18 }
19
20 public static boolean hasValidNext(int i) {
21 if (i == 0) {
22 return false;
23 }
24 int count = 0;
25 while ((i & 1) == 0) {
26 i >>= 1;
27 count++;
28 }
29 while ((i & 1) == 1) {
30 i >>= 1;
31 count++;
32 }
33 if (count == 31) {
34 return false;
35 }
36 return true;
37 }
38
39 public static boolean hasValidPrev(int i) {
40 while ((i & 1) == 1) {

Callers 1

getNextSlowMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected