# Input:"0", "1" , my code is correct in eclipse ("1") but error in OJ ("101" )

• ``````public class Solution
{

{
String temp = "";
String c = null;
if(a.equals("0")&&b.equals("0")) return "0";
if(a.length()==0 && b.length()==0) {return "";}
else if(a.length()==0){return b;}
else if(b.length()==0){return a;}

else
{
if(a.length()>b.length())
{
for(int i=0;i<a.length()-b.length();i++)
{
temp+="0";

}
temp+=b;
//      System.out.println("@"+temp);
c=cal(a,temp);

}

else if(b.length()>a.length())
{
for(int i=0;i<b.length()-a.length();i++)
{
temp+="0";

}
temp+=a;
c=cal(temp,b);
}
else
{
c=cal(a,b);

}
}

String[] cc=c.split("");

for(int i=cc.length-1;i>=0;i--)
{

}

}
public  String cal(String aa,String bb)
{
String[] a=aa.split("");
String[] b=bb.split("");

String c="";

for(int i=a.length-1;i>=0;i--)
{
if(a[i].equals("0")){ia=0;} else{ia=1;}
if(b[i].equals("0")){ib=0;} else{ib=1;}

}
if(ic==1) {c+="1";}
return c;

}``````

• Lachao,

Just tested in Eclipse. The code was not right in cal("0", "1");

If you define a variable for the string length, you will catch.

int l = a.length; // l == 2

then the second loop:

a[0] is "", you set it with ia = 1;
b[0] is "", you set it as ib = 1;
So you iadd = 2, then ic = 1;

Just change your program as following:

``````        if(a[i].equals("1")){ia=1;} else{ia=0;}
if(b[i].equals("1")){ib=1;} else{ib=0;}
``````

You problem will be resolved.

Good luck,
Peng

• thanks for your answer:), it really help me to pass the "101" output problem, but it face another wrong output "01" with the same test case "0","1". (the output is also correct in my eclipse code)

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.