import java.util.*;
// 多个判断就行
public class Solution {
/**
*
* @param str string字符串
* @return int整型
*/
public int atoi (String str) {
// write code here
char[] chars = str.toCharArray();
int i = 1;
int ret = 0;
Set<Character> set = new HashSet<>();
set.add('0');
set.add('1');
set.add('2');
set.add('3');
set.add('4');
set.add('5');
set.add('6');
set.add('7');
set.add('8');
set.add('9');
int mins = 0;
for (char c : chars) {
if (i == 1) {
if (c == '+' || c == '-') {
if (c == '-') {
mins = 1;
}
continue;
}
if (!set.contains(c)) {
if (' ' == c) {
continue;
}
return 0;
}
}
if (!set.contains(c)) {
if (' ' == c) {
continue;
}
if (mins == 1) {
return -ret;
}
return ret;
}
ret = 10 * ret + (c - '0');
i++;
}
if (mins == 1) {
return -ret;
}
return ret;
}
}