1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-05 15:31:43 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/有效数字 [valid-number].html
2025-01-09 20:29:41 +08:00

60 lines
2.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定一个字符串&nbsp;<code>s</code>&nbsp;,返回&nbsp;<code>s</code>&nbsp;是否是一个 <strong>有效数字</strong></p>
<p>例如,下面的都是有效数字:<code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"</code>,而接下来的不是:<code>"abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"</code></p>
<p>一般的,一个 <strong>有效数字</strong>&nbsp;可以用以下的规则之一定义:</p>
<ol>
<li>一个 <strong>整数</strong> 后面跟着一个 <strong>可选指数</strong></li>
<li>一个 <strong>十进制数</strong> 后面跟着一个&nbsp;<strong>可选指数</strong></li>
</ol>
<p>一个 <strong>整数</strong> 定义为一个&nbsp;<strong>可选符号</strong>&nbsp;<code>'-'</code>&nbsp;&nbsp;<code>'+'</code>&nbsp;后面跟着 <strong>数字</strong></p>
<p>一个 <strong>十进制数</strong>&nbsp;定义为一个&nbsp;<strong>可选符号&nbsp;</strong><code>'-'</code>&nbsp;&nbsp;<code>'+'</code>&nbsp;后面跟着下述规则:</p>
<ol>
<li><strong>数字&nbsp;</strong>后跟着一个 <strong>小数点&nbsp;<code>.</code></strong></li>
<li><strong>数字&nbsp;</strong>后跟着一个 <strong>小数点&nbsp;<code>.</code>&nbsp;</strong>再跟着<strong> 数位</strong></li>
<li>一个 <strong>小数点&nbsp;<code>.</code>&nbsp;</strong>后跟着<strong> 数位</strong></li>
</ol>
<p><strong>指数</strong> 定义为指数符号 <code>'e'</code><code>'E'</code>,后面跟着一个 <b>整数</b></p>
<p><strong>数字</strong>&nbsp;定义为一个或多个数位。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "0"</span></p>
<p><strong>输出:</strong><span class="example-io">true</span></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "e"</span></p>
<p><strong>输出:</strong><span class="example-io">false</span></p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "."</span></p>
<p><strong>输出:</strong><span class="example-io">false</span></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 20</code></li>
<li><code>s</code> 仅含英文字母(大写和小写),数字(<code>0-9</code>),加号 <code>'+'</code> ,减号 <code>'-'</code> ,或者点 <code>'.'</code></li>
</ul>