65. Valid Number Hard
1/**
2 * [65] Valid Number
3 *
4 * A valid number can be split up into these components (in order):
5 * <ol>
6 * A decimal number or an integer.
7 * (Optional) An 'e' or 'E', followed by an integer.
8 * </ol>
9 * A decimal number can be split up into these components (in order):
10 * <ol>
11 * (Optional) A sign character (either '+' or '-').
12 * One of the following formats:
13 * <ol>
14 * One or more digits, followed by a dot '.'.
15 * One or more digits, followed by a dot '.', followed by one or more digits.
16 * A dot '.', followed by one or more digits.
17 * </ol>
18 *
19 * </ol>
20 * An integer can be split up into these components (in order):
21 * <ol>
22 * (Optional) A sign character (either '+' or '-').
23 * One or more digits.
24 * </ol>
25 * For example, all the following are valid numbers: ["2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"], while the following are not valid numbers: ["abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"].
26 * Given a string s, return true if s is a valid number.
27 *
28 * Example 1:
29 *
30 * Input: s = "0"
31 * Output: true
32 *
33 * Example 2:
34 *
35 * Input: s = "e"
36 * Output: false
37 *
38 * Example 3:
39 *
40 * Input: s = "."
41 * Output: false
42 *
43 *
44 * Constraints:
45 *
46 * 1 <= s.length <= 20
47 * s consists of only English letters (both uppercase and lowercase), digits (0-9), plus '+', minus '-', or dot '.'.
48 *
49 */
50pub struct Solution {}
51
52// problem: https://leetcode.com/problems/valid-number/
53// discuss: https://leetcode.com/problems/valid-number/discuss/?currentPage=1&orderBy=most_votes&query=
54
55// submission codes start here
56
57impl Solution {
58 pub fn is_number(s: String) -> bool {
59 false
60 }
61}
62
63// submission codes end
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
70 fn test_65() {
71 }
72}
73
Back
© 2025 bowen.ge All Rights Reserved.