- Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSuperIncreasing.java
28 lines (22 loc) · 709 Bytes
/
SuperIncreasing.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
importjava.util.*;
importjava.io.*;
classMain {
publicstaticStringMathChallenge(Stringstr) {
// code goes here
for(charitem : str.toCharArray())
if(!(item == '0' || item == '1'))
return"Argument Exception";
doubleacc = 0;
for(inti = 0; i< str.length(); i ++)
{
intnum = Integer.parseInt(String.valueOf(str.charAt(i)));
acc += num * Math.pow(2, str.length() - 1 - i);
}
returnString.valueOf((int)acc);
}
publicstaticvoidmain (String[] args) {
// keep this function call here
Scanners = newScanner(System.in);
System.out.print(MathChallenge(s.nextLine()));
}
}