题目描述
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ccd02393b7c849566db1ec39ab61bb21.png)
解题思路
class Solution {
public boolean isNumber(String s) {
if (s == null || s.length() == 0) return false;
boolean isNum = false, isDot = false, ise_or_E = false;
char[] str = s.trim().toCharArray();
for (int i = 0; i < str.length; i++) {
if (str[i] >= '0' && str[i] <= '9') {
isNum = true;
} else if (str[i] == '.') {
if (isDot || ise_or_E) return false;
isDot = true;
} else if (str[i] == 'e' || str[i] == 'E') {
if (!isNum || ise_or_E) return false;
ise_or_E = true;
isNum = false;
} else if (str[i] == '+' || str[i] == '-') {
if (i != 0 && str[i - 1] != 'e' && str[i - 1] != 'E') return false;
} else {
return false;
}
}
return isNum;
}
}