Closed mcrwayfun closed 5 years ago
method1 and method2 can get same answer , but the time complexity of method2 is O(n) while method1 is O(n^2)
// method1 private boolean isBit1(int val, int index) { for (int i = 0; i < index; ++i) { val = val >> 1; } return (val & 1) == 1; } // method2 private boolean isBit1(int val, int index) { val = val >> index; return (val & 1) == 1; }
method1 and method2 can get same answer , but the time complexity of method2 is O(n) while method1 is O(n^2)