[Hackerrank] maximizing XOR

Source: Internet
Author: User

Given two integers:LAndR

Limit L ≤ A ≤ B ≤ r, find outAXORB.

Input Format

The first line containsLThe first line containsR

Data range

1 ≤ L ≤ r ≤103

Output Format

Maximum exclusive or sum of outputs

Question:

 1 import java.io.*; 2 import java.util.*; 3 import java.text.*; 4 import java.math.*; 5 import java.util.regex.*; 6  7 public class Solution { 8 /* 9  * Complete the function below.10  */11 12     static int maxXor(int l, int r) {13         int maxx = 0;14         for(int i = l;i <= r;i++){15             for(int j = l;j <= r;j++){16                 if(i != j)17                     maxx = Math.max(maxx,i^j);18             }19         }20         return maxx;21 22     }23 24     public static void main(String[] args) {25         Scanner in = new Scanner(System.in);26         int res;27         int _l;28         _l = Integer.parseInt(in.nextLine());29         30         int _r;31         _r = Integer.parseInt(in.nextLine());32         33         res = maxXor(_l, _r);34         System.out.println(res);35         36     }37 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.