2021年9月17日00:08:11
2021年9月17日00:18:45
public class Solution {
public int StrToInt(String str) {
if(str.length()==0) return 0;
boolean flag = false;
if(str.charAt(0) == '+' || str.charAt(0) == '-'){
if(str.charAt(0) == '-') flag= true;
if(str.length()==1) return 0;
str=str.substring(1,str.length());
}
for(char c: str.toCharArray()){
if(c>'9' || c<'0') return 0;
}
int res = 0;
for(char c: str.toCharArray()){
res = res*10 + c - '0';
}
return flag? -res:res;
}
}


京公网安备 11010502036488号