Problem:
Given a binary number, Find, if given binary number is a multiple of 3. The given number can be big upto 2^10000. It is recommended to finish the task using one traversal of input binary string.
Example 1:
Input: S = "011"
Output: 1
Explanation: "011" decimal equivalent
is 3, which is divisible by 3.
My Answer:
int isDivisible(String s) { // code here\ java.math.BigInteger bInt = new java.math.BigInteger(s, 2); if ( bInt.mod(new java.math.BigInteger("3")) == java.math.BigInteger.ZERO ) { return 1; } return 0; }
No comments:
Post a Comment