We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cb1121c commit 9caa2ccCopy full SHA for 9caa2cc
Medium/string_to_integer_atoi.go
@@ -29,15 +29,16 @@ func myAtoi(s string) int {
29
collectString = collectString + string(s[i])
30
}
31
32
+ if len(collectString) >= 20 {
33
+ if isNegative {
34
+ return -(1 << 31)
35
+ } else {
36
+ return (1 << 31) - 1
37
+ }
38
39
+
40
resultInt, err := strconv.Atoi(collectString)
41
if err != nil {
- if len(collectString) > 5 {
- if isNegative {
- return -(1 << 31)
- } else {
- return (1 << 31) - 1
- }
42
return 0
43
44
0 commit comments