Leetcode - Bitwise AND of Numbers Range
My code:
public class Solution {
public int rangeBitwiseAnd(int m, int n) {
int i = 1;
while (m != n) {
m >>= 1;
n >>= 1;
i <<= 1;
}
return m * i;
}
}
reference:
一開始看了這個最優解
https://discuss.leetcode.com/topic/12133/bit-operation-solution-java
不明白為什麼最後 m * iteration
然後看了這個:
http://www.cnblogs.com/grandyang/p/4431646.html
更加形象,就理解了。
Anyway, Good luck, Richardo! -- 10/14/2016
相關文章
- LeetCode-Bitwise AND of Numbers RangeLeetCode
- 201-Bitwise AND of Numbers Range
- [leetcode] 898. Bitwise ORs of SubarraysLeetCode
- LeetCode-Lexicographical NumbersLeetCode
- Leetcode Search for a RangeLeetCode
- Leetcode Sum Root to Leaf NumbersLeetCode
- Leetcode Add Two NumbersLeetCode
- [LeetCode] 2419. Longest Subarray With Maximum Bitwise ANDLeetCode
- LeetCode 34 Search for a RangeLeetCode
- Leetcode-Search for a rangeLeetCode
- Search for a Range leetcode javaLeetCodeJava
- LeetCode 2 Add Two NumbersLeetCode
- Leetcode-Add Two NumbersLeetCode
- Sum Root to Leaf Numbers leetcode javaLeetCodeJava
- Add Two Numbers leetcode javaLeetCodeJava
- leetcode34_Search for a RangeLeetCode
- LeetCode-Range AdditionLeetCode
- LeetCode-Count of Range SumLeetCode
- Leetcode 165 Compare Version NumbersLeetCode
- Leetcode 967 Numbers With Same Consecutive DifferencesLeetCode
- LeetCode-2 Add Two NumbersLeetCode
- LeetCode 2. Add Two NumbersLeetCode
- Leetcode[421] Maximum XOR of Two Numbers in an ArrayLeetCode
- LeetCode- Count Numbers with Unique DigitsLeetCodeGit
- leetcode刷題--Compare Version NumbersLeetCode
- LeetCode OJ : 2 Add Two NumbersLeetCode
- LeetCode-Range Sum Query - MutableLeetCode
- LeetCode 129. Sum Root to Leaf NumbersLeetCode
- [leetCode][016] Add Two NumbersLeetCode
- LeetCode129:Sum Root to Leaf NumbersLeetCode
- LeetCode之Smallest Range I(Kotlin)LeetCodeKotlin
- LeetCode-Range Sum Query- ImmutableLeetCode
- [LeetCode] 910. Smallest Range IILeetCode
- LeetCode之Sum of Even Numbers After Queries(Kotlin)LeetCodeKotlin
- LeetCode 448. Find All Numbers Disappeared in an ArrayLeetCodeAPP
- [Leetcode] 2. Add Two Numbers QuestionEditorial SolutionLeetCode
- LeetCode2: Add two numbers(兩數相加)LeetCode
- [LeetCode] Add Two Numbers 兩個數字相加LeetCode