Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jiang feng
leetcode-Python
Commits
c970b54b
Commit
c970b54b
authored
Mar 18, 2026
by
jiang feng
Browse files
Upload New File
parent
16c80f8b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
01/8.py
01/8.py
+38
-0
No files found.
01/8.py
0 → 100644
View file @
c970b54b
class
Solution
:
def
myAtoi
(
self
,
str
):
"""
:type str: str
:rtype: int
"""
str
=
str
.
strip
()
number
=
""
for
x
in
str
:
if
x
.
isalpha
()
and
number
==
""
:
return
0
elif
x
.
isalpha
():
break
elif
x
==
"."
:
break
elif
x
==
" "
:
break
elif
(
x
==
"+"
or
x
==
"-"
)
and
number
==
""
:
number
=
number
+
x
elif
(
x
==
"+"
or
x
==
"-"
)
and
number
!=
""
:
break
elif
(
x
==
"+"
or
x
==
"-"
)
and
(
number
[
-
1
]
==
"+"
or
number
[
-
1
]
==
"-"
):
return
0
elif
(
x
==
"+"
or
x
==
"-"
)
and
(
"+"
in
number
or
"-"
in
number
):
break
elif
x
.
isdigit
():
number
=
number
+
x
if
number
==
""
or
number
==
"+"
or
number
==
"-"
:
return
0
else
:
if
int
(
number
)
>
((
2
**
31
)
-
1
):
return
(
2
**
31
)
-
1
elif
int
(
number
)
<
-
(
2
**
31
):
return
-
(
2
**
31
)
else
:
return
int
(
number
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment