FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python_primer/atoi.py at master · robot527/python_primer · GitHub
robot527
/
python_primer
Public
Notifications
You must be signed in to change notification settings
Fork
9
Star
5
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python_primer
/
atoi.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
24 lines (19 loc) · 584 Bytes
Breadcrumbs
python_primer
/
atoi.py
Copy path
File metadata and controls
24 lines (19 loc) · 584 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# author: luoyaozu
"""
https://leetcode-cn.com/problems/string-to-integer-atoi/
Implement atoi which converts a string to an integer.
"""
def
my_atoi
(
s
):
import
re
return
max
(
min
(
int
(
*
re
.
findall
(
r'^[+-]?\d+'
,
s
.
lstrip
())), (
1
<<
31
)
-
1
),
-
(
1
<<
31
))
if
__name__
==
'__main__'
:
print
my_atoi
(
"123"
)
print
my_atoi
(
" -32"
)
print
my_atoi
(
"4193 with words"
)
print
my_atoi
(
"words and 987"
)
print
my_atoi
(
"-91283472332"
)
print
my_atoi
(
"+91283472332236"
)
print
my_atoi
(
"0xab"
)
print
my_atoi
(
"ab"
)
Back
|
FazBrowse Home
|
New Git URL