题目地址:
https://www.lintcode.com/problem/valid-number/description
给定一个字符串,问其是否能解析为数字。
直接用java的语言特性即可。代码如下:
public class Solution {
/**
* @param s: the string that represents a number
* @return: whether the string is a valid number
*/
public boolean isNumber(String s) {
// write your code here
try {
Double.parseDouble(s);
} catch (Exception e) {
return false;
}
return true;
}
}
时空复杂度与parseDouble的实现有关。