Update 20. 表示数值的字符串.md

题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
CyC2018
2026-10-28 13:45:04 +08:00
parent dcd2f82501
commit 8c9f4191b5
+4 -4
View File
@@ -1,6 +1,6 @@
# 20. 表示数值的字符串
[牛客网](https://www.nowcoder.com/practice/e69148f8528c4039ad89bb2546fd4ff8?tpId=13&tqId=11206&tab=answerKey&from=cyc_github)
[Leetcode](https://leetcode.cn/problems/biao-shi-shu-zhi-de-zi-fu-chuan-lcof/)
## 题目描述
@@ -41,9 +41,9 @@ false
```
```java
public boolean isNumeric (String str) {
if (str == null || str.length() == 0)
public boolean validNumber(String s) {
if (s == null || s.length() == 0)
return false;
return new String(str).matches("[+-]?\\d*(\\.\\d+)?([eE][+-]?\\d+)?");
return s.trim().matches("[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?");
}
```