Package g0001_0100.s0065_valid_number
Class Solution
java.lang.Object
g0001_0100.s0065_valid_number.Solution
65 - Valid Number.<p>Hard</p>
<p>A <strong>valid number</strong> can be split up into these components (in order):</p>
<ol>
<li>A <strong>decimal number</strong> or an <strong>integer</strong>.</li>
<li>(Optional) An <code>'e'</code> or <code>'E'</code>, followed by an <strong>integer</strong>.</li>
</ol>
<p>A <strong>decimal number</strong> can be split up into these components (in order):</p>
<ol>
<li>(Optional) A sign character (either <code>'+'</code> or <code>'-'</code>).</li>
<li>One of the following formats:
<ol>
<li>One or more digits, followed by a dot <code>'.'</code>.</li>
<li>One or more digits, followed by a dot <code>'.'</code>, followed by one or more digits.</li>
<li>A dot <code>'.'</code>, followed by one or more digits.</li>
</ol>
</li>
</ol>
<p>An <strong>integer</strong> can be split up into these components (in order):</p>
<ol>
<li>(Optional) A sign character (either <code>'+'</code> or <code>'-'</code>).</li>
<li>One or more digits.</li>
</ol>
<p>For example, all the following are valid numbers: <code>["2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"]</code>, while the following are not valid numbers: <code>["abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"]</code>.</p>
<p>Given a string <code>s</code>, return <code>true</code> <em>if</em> <code>s</code> <em>is a <strong>valid number</strong></em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “0”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “e”</p>
<p><strong>Output:</strong> false</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “.”</p>
<p><strong>Output:</strong> false</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> s = “.1”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 20</code></li>
<li><code>s</code> consists of only English letters (both uppercase and lowercase), digits (<code>0-9</code>), plus <code>'+'</code>, minus <code>'-'</code>, or dot <code>'.'</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isNumber
-