当前位置:网站首页>Leetcode String to integer(Atoi)
Leetcode String to integer(Atoi)
2022-06-10 17:41:00 【Artificial intelligence Zeng Xiaojian】
^: Match the beginning of a string
[\+\-]: Representing one + Character or - character
?: The first character is optional
\d: A number
+: One or more of the preceding characters
\D: A non numeric character
*: The first character 0 One or more
class Solution:
def myAtoi(self, s: str) -> int:
return max(min(int(*re.findall('^[\+\-]?\d+', s.lstrip())), 2**31 - 1), -2**31)
import re
class Solution:
def myAtoi(self, str: str) -> int:
INT_MAX = 2147483647
INT_MIN = -2147483648
str = str.lstrip() # Clear the extra space on the left
num_re = re.compile(r'^[\+\-]?\d+') # Set regular rules
num = num_re.findall(str) # Find a match
num = int(*num) # Because it returns a list , Unpack and convert to integer
return max(min(num,INT_MAX),INT_MIN) # Return value import re
class Solution:
def myAtoi(self,str:str) -> int:
INT_MAX = 2**31-1
INT_MIN = -2**31
str = str.lstrip()边栏推荐
- KDD 2021 | MoCL:利用多层次领域知识的分子图对比学习
- 牛客网:两数之和
- 【报表工具的第二次革命】基于SPL语言优化报表结构、提升报表运算性能
- Installing kubernetes using kuboardspray (v1.23.1)
- 丢失的遗传力--Missing heritability
- Full link tracking & performance monitoring tool skywalking practice
- Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
- Online communication skill network: a sparse model for solving multi task and multi-modal problems (Qingyuan talk, issue 19, tangduyu)
- Fabric. JS centered element
- Mysql database implementation setting field length
猜你喜欢

pands pd.DataFrame()函数详细解析

Station B doesn't want to be a "conscience aiyouteng"

【报表工具的第二次革命】基于SPL语言优化报表结构、提升报表运算性能

Chongqing's first sci tech Innovation Board IPO is coming

Nacos注册中心

Xinsi technology helps Israel visuality systems promote the "left shift" of security

mapbox-gl开发教程(十一):加载线图层

Web3最全搞钱秘籍,看这一篇就够了

2022G1工业锅炉司炉考题及在线模拟考试

品牌难立,IPO难行,中国茶企困于“传统”?
随机推荐
Fabric. JS centered element
虚拟机ping不通的几种原因及解决办法
蓝桥杯_挑选子串_组合数学_乘法原理_ / 尺取法
Brands are difficult to establish, IPO is difficult, and Chinese tea enterprises are trapped in "tradition"?
成立1年便成独角兽,腾讯滴滴做「靠山」,今年新晋的独角兽不简单
海外数据中心需要为不可预测的灾难做好准备
Nacos configuration management
Take you to a preliminary understanding of the basic mechanism of classes and objects
聊聊消息中间件(1),AMQP那些事儿
Redis operation set, Zset, hash data types and use of visualization tools
vscode常用快捷键
Importerror: libgl.so.1: cannot open shared object file: no such file or directory
二十多年了,安全套市场还只有杜蕾斯、冈本、杰士邦
Fabric.js 缩放画布
2022G1工业锅炉司炉考题及在线模拟考试
Graduation season: to you
KDD 2021 | MoCL:利用多层次领域知识的分子图对比学习
Richard Behrman, the founder of dynamic planning
Lifeifei: I am more like a scientist in physics than an engineer
Full link tracking & performance monitoring tool skywalking practice