当前位置:网站首页>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()边栏推荐
- Knowledge-based BERT: 像计算化学家一样提取分子特征的方法
- 力扣 20. 有效的括号
- 基于DeepFace模型设计的人脸识别软件
- Simple site backup shell script
- Thread interview related questions
- Knowledge based bert: a method to extract molecular features like a computational chemist
- 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
- 每日一题-1287. 有序数组中出现次数超过25%的元素
- KDD 2021 | MoCl: comparative learning of molecular graphs using multi-level domain knowledge
猜你喜欢

Solve the problem that idea is stuck in opening a project

如何运行plink软件--三种方法

C#_串口通信项目

为什么 0.1+0.2=0.30000000000000004

C#_ Serial port communication project

二十多年了,安全套市场还只有杜蕾斯、冈本、杰士邦

Gateway服务网关

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

Nacos configuration management

SVN中的回退操作
随机推荐
Nacos注册中心
Richard Behrman, the founder of dynamic planning
安全感
[the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language
Nat. Commun. | 用于加速发现抗生素抗性基因的知识整合和决策支持
域名备案和icp备案有哪些区别?
Swing visualization plug-in jformdesigner of idea
Designing drugs with code: are we here yet?
目标客户匹配数据表格成功案例展示
AIChE | ab initio drug design framework integrating mathematical programming method and deep learning model
Thread interview related questions
2022年茶艺师(中级)操作证考试题库及模拟考试
Fabric.js 缩放画布
Swift 3pThread tool Promise Pipeline Master/Slave Serial Thread confinement Serial queue
【玩转华为云】手把手带你使用鲲鹏代码迁移工具实现源码迁移
新思科技在《 2022 年 Gartner 应用安全测试关键能力报告》中表现优异 在五个常见用例中荣获最高分
绘制混淆矩阵
A few misunderstandings about programmers are very harmful!
Fabric.js 激活输入框
Make good use of the industrial chain to attract investment, create industrial cluster effect and realize the coordinated development of industries