-1
LeetCode 문제 역방향 정수에 대한 코드를 작성합니다. 내 솔루션에 문제가 있는지 찾을 수는 없지만 LeetCode 공식 사이트에서이를 실행하면이 런타임 오류가 전파됩니다.어떻게 해결이 java.lang.NumberFormatException : 입력 문자열 : ""내 코드를 기반으로?
class Solution {
public int reverse(int x)
{
String resultStr = "";
int result = 0;
boolean isNegative = false;
if(x < 0)
{
isNegative = true;
}
int integer = Math.abs(x);
int divid = integer;
while(divid!= 0)
{
divid = divid/10;
resultStr += integer%10;
integer = divid;
}
result = Integer.parseInt(resultStr);
if(isNegative)
{
result = 0-result;
}
return result;
}
}
'경우 resultStr.equals ("")'int''로 분석하기 전에. 'divid'가'0'이면'resultStr'는 비어 있습니다. – BackSlash
좋은 캐치. 감사. – user7027796