当前位置:网站首页>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()边栏推荐
- 域名备案和icp备案有哪些区别?
- 【AXI】解读AXI协议双向握手机制的原理
- 自定义视图:图形与图像的处理(一):使用简单图片
- Designing drugs with code: are we here yet?
- The children in the deep mountains are seeing the stars farther away
- Chongqing's first sci tech Innovation Board IPO is coming
- 品牌难立,IPO难行,中国茶企困于“传统”?
- 路由器实验之serial接口的静态路由配置(补充)
- Xinsi technology performed well in the Gartner application security test key capability report 2022 and won the highest score among the five common use cases
- 2022年T电梯修理考试题模拟考试题库及在线模拟考试
猜你喜欢

2022年茶艺师(中级)操作证考试题库及模拟考试

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

丢失的遗传力--Missing heritability

企鹅电竞停步,虎牙也难行

2022年上海市安全员C证操作证考试题库模拟考试平台操作

Swift 3pThread tool Promise Pipeline Master/Slave Serial Thread confinement Serial queue

Web3 is the most complete money making secret script. Just read this one

Nacos配置管理

聊聊消息中间件(1),AMQP那些事儿

蓝桥杯_挑选子串_组合数学_乘法原理_ / 尺取法
随机推荐
Force buckle 20 Valid parentheses
AlphaFold 和 NMR 测定溶液中蛋白质结构的准确性
【抬杠C#】如何实现接口的base调用
Redis通用指令
力扣 20. 有效的括号
基于DeepFace模型设计的人脸识别软件
2022G1工业锅炉司炉考题及在线模拟考试
Knowledge-based BERT: 像计算化学家一样提取分子特征的方法
运筹说 第64期丨动态规划奠基人——理查德·贝尔曼
Cap version 6.1 Release Notice
Fabric. Keep the original level when JS element is selected
嘿!ONES 新星请看过来|师兄师姐说
AHK common functions
Nacos注册中心
KDD 2021 | MoCL:利用多层次领域知识的分子图对比学习
2022版IDEA图形界面GUI乱码解决方法超详细简单版
When V-IF and V-for need to be used at the same time
蓝桥杯_挑选子串_组合数学_乘法原理_ / 尺取法
自定义视图:图形与图像的处理(一):使用简单图片
Fabric.js 缩放画布