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
相關文章
- 201-Bitwise AND of Numbers Range
- [leetcode] 898. Bitwise ORs of SubarraysLeetCode
- [LeetCode] 2419. Longest Subarray With Maximum Bitwise ANDLeetCode
- LeetCode 2 Add Two NumbersLeetCode
- Leetcode 165 Compare Version NumbersLeetCode
- [LeetCode] 2275. Largest Combination With Bitwise AND Greater Than ZeroLeetCode
- LeetCode-2 Add Two NumbersLeetCode
- LeetCode 2. Add Two NumbersLeetCode
- Leetcode 967 Numbers With Same Consecutive DifferencesLeetCode
- LeetCode 129. Sum Root to Leaf NumbersLeetCode
- LeetCode之Smallest Range I(Kotlin)LeetCodeKotlin
- [LeetCode] 2080. Range Frequency QueriesLeetCode
- [LeetCode] 910. Smallest Range IILeetCode
- LeetCode之Sum of Even Numbers After Queries(Kotlin)LeetCodeKotlin
- LeetCode 448. Find All Numbers Disappeared in an ArrayLeetCodeAPP
- LeetCode2: Add two numbers(兩數相加)LeetCode
- Fifth. LeetCode 2:Add Two Numbers 兩數之和LeetCode
- Leetcode 1365. How Many Numbers Are Smaller Than the Current Number (cpp)LeetCode
- [Typescript] Use Bitwise FlagsTypeScript
- OpenCV(cv::bitwise_not())OpenCV
- leetcode 兩數相加(add two numbers) Python程式設計實現LeetCodePython程式設計
- 常用的JavaScript位操作(Bitwise)JavaScript
- Reversed Numbers
- 【Leetcode】1689. Partitioning Into Minimum Number Of Deci-Binary Numbers(配數學證明)LeetCode
- 400多種Numbers模板 DesiGN for Numbers Templates for macMac
- Collecting Numbers II
- Codeforces - Jzzhu and Numbers
- 演算法練習--LeetCode--129. Sum Root to Leaf Numbers; Runtime: 8 ms100%演算法LeetCode
- different random numbers generatorrandom
- HTML input rangeHTML
- Range Sparse Net
- Range Minimum Sum
- python-rangePython
- for range 作用域
- 【leetcode】34. Search for a Range 給定陣列的給定值的下標範圍LeetCode陣列
- Find All Numbers Disappeared in an ArrayAPP
- 165. Compare Version Numbers
- 829. Consecutive Numbers Sum
- 【Lintcode】1267. Lexicographical Numbers