-
Notifications
You must be signed in to change notification settings - Fork 160
/
valid-number.md
31 lines (26 loc) · 1.72 KB
/
valid-number.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<p>Validate if a given string can be interpreted as a decimal number.</p>
<p>Some examples:<br />
<code>"0"</code> => <code>true</code><br />
<code>" 0.1 "</code> => <code>true</code><br />
<code>"abc"</code> => <code>false</code><br />
<code>"1 a"</code> => <code>false</code><br />
<code>"2e10"</code> => <code>true</code><br />
<code>" -90e3 "</code> => <code>true</code><br />
<code>" 1e"</code> => <code>false</code><br />
<code>"e3"</code> => <code>false</code><br />
<code>" 6e-1"</code> => <code>true</code><br />
<code>" 99e2.5 "</code> => <code>false</code><br />
<code>"53.5e93"</code> => <code>true</code><br />
<code>" --6 "</code> => <code>false</code><br />
<code>"-+3"</code> => <code>false</code><br />
<code>"95a54e53"</code> => <code>false</code></p>
<p><strong>Note:</strong> It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one. However, here is a list of characters that can be in a valid decimal number:</p>
<ul>
<li>Numbers 0-9</li>
<li>Exponent - "e"</li>
<li>Positive/negative sign - "+"/"-"</li>
<li>Decimal point - "."</li>
</ul>
<p>Of course, the context of these characters also matters in the input.</p>
<p><strong>Update (2015-02-10):</strong><br />
The signature of the <code>C++</code> function had been updated. If you still see your function signature accepts a <code>const char *</code> argument, please click the reload button to reset your code definition.</p>