forked from bamsarts/DS-ALGO
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from guruc-134/patch-9
Create MaximizingXOR
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
Given two integers,l and r, find the maximal value of a xor b, where a and b satisfy the following condition: | ||
l<=a<=b<=r | ||
|
||
example: | ||
l=11 | ||
r=12 | ||
ans=7 | ||
|
||
the maximizingXor function It must return an integer representing the maximum value calculated. | ||
maximizingXor has the following parameter(s): | ||
|
||
l: an integer, the lower bound, inclusive | ||
r: an integer, the upper bound, inclusive | ||
|
||
""" | ||
def maximizingXor(l, r): | ||
m=0 | ||
for i in range(l,r+1): | ||
for j in range(i,r+1): | ||
xor=i^j | ||
m=max(m,xor) | ||
return m | ||
|