From 8c9f4191b5320eabee7a66d7bb017f24c4d2885c Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Wed, 28 Oct 2026 13:45:04 +0800 Subject: [PATCH] =?UTF-8?q?Update=2020.=20=E8=A1=A8=E7=A4=BA=E6=95=B0?= =?UTF-8?q?=E5=80=BC=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。 --- notes/20. 表示数值的字符串.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/notes/20. 表示数值的字符串.md b/notes/20. 表示数值的字符串.md index 60527c11..0990b2e0 100644 --- a/notes/20. 表示数值的字符串.md +++ b/notes/20. 表示数值的字符串.md @@ -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+)?"); } ```