件名:https : //leetcode-cn.com/problems/string-to-integer-atoi/
回答:文字列
public int myAtoi(String str){
str = str.trim();
int len = str.length();
if(len == 0)は0を返します。
char [] chars = str.toCharArray();
ブール負= false;
intインデックス= 0;
if(chars [index] == '-'){
負=真;
index ++;
} else if(chars [index] == '+'){
index ++;
} else if(!Character.isDigit(chars [index])){
0を返します。
}
int年= 0;
while(index <len && Character.isDigit(chars [index])){
int digit = chars [index]-'0';
if(ans>(Integer.MAX_VALUE-digit)/ 10){
マイナスを返す?Integer.MIN_VALUE:Integer.MAX_VALUE;
}
年=年* 10 +桁;
index ++;
}
マイナスを返す?-ans:ans;
}