-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path65-ValidNumber.go
More file actions
54 lines (49 loc) · 974 Bytes
/
Copy path65-ValidNumber.go
File metadata and controls
54 lines (49 loc) · 974 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"strings"
)
func isNumber(s string) bool {
fmt.Println(strings.Join(parseNumber(s), ", "))
return true
}
func parseNumber(s string) []string {
if len(s) > 0 {
curr := s[0]
if !isDigit(curr) && !isOperator(curr) {
return append(parseNumber(s[1:]), "letter")
}
if curr == ' ' {
return append(parseNumber(s[1:]), "space")
}
if curr == 'e' {
return append(parseNumber(s[1:]), "exp")
}
for i := 1; i < len(s); i++ {
if (!isDigit(curr) && !isOperator(curr)) || curr == ' ' || curr == 'e' || i == len(s)-1 {
fmt.Println(i, string(curr), "-"+s[0:i]+"-")
return append(parseNumber(s[i+1:]), "xx")
}
}
}
return []string{}
}
func isDigit(s byte) bool {
return s == '0' ||
s == '1' ||
s == '2' ||
s == '3' ||
s == '4' ||
s == '5' ||
s == '6' ||
s == '7' ||
s == '8' ||
s == '9'
}
func isOperator(s byte) bool {
return s == '+' ||
s == '-' ||
s == 'e' ||
s == '.' ||
s == ' '
}