public class solution {
public static int convertStringToInt
(String input
){
return convertStringToIntHelper(input, 0, 0);
}
public static int convertStringToIntHelper
(String input,
int idx,
int ans
){
if (idx == input.length()-1) {
int val = input.charAt(idx) - '0';
ans = ans * 10 + val;
return ans;
}
int val = input.charAt(idx) - '0';
ans = ans * 10 + val;
return convertStringToIntHelper(input, idx+1, ans);
}
}
CnB1YmxpYyBjbGFzcyBzb2x1dGlvbiB7CgoJcHVibGljIHN0YXRpYyBpbnQgY29udmVydFN0cmluZ1RvSW50KFN0cmluZyBpbnB1dCl7CgkJCgoJCXJldHVybiBjb252ZXJ0U3RyaW5nVG9JbnRIZWxwZXIoaW5wdXQsIDAsIDApOwoJfQoKCXB1YmxpYyBzdGF0aWMgaW50IGNvbnZlcnRTdHJpbmdUb0ludEhlbHBlcihTdHJpbmcgaW5wdXQsIGludCBpZHgsIGludCBhbnMpewoKCQlpZiAoaWR4ID09IGlucHV0Lmxlbmd0aCgpLTEpIHsKCgkJCWludCB2YWwgPSBpbnB1dC5jaGFyQXQoaWR4KSAtICcwJzsKCQkJYW5zID0gYW5zICogMTAgKyB2YWw7CgoJCQlyZXR1cm4gYW5zOwoJCX0KCgkJaW50IHZhbCA9IGlucHV0LmNoYXJBdChpZHgpIC0gJzAnOwoKCQlhbnMgPSBhbnMgKiAxMCArIHZhbDsKCgkJcmV0dXJuIGNvbnZlcnRTdHJpbmdUb0ludEhlbHBlcihpbnB1dCwgaWR4KzEsIGFucyk7CQkKCX0KfQo=