当前位置:网站首页>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()边栏推荐
猜你喜欢
随机推荐
力扣 20. 有效的括号
Full link tracking & performance monitoring tool skywalking practice
What are the differences between domain name filing and ICP filing?
域名备案和icp备案有哪些区别?
Leetcode String to integer(Atoi)
Set up proxy for chocolate
com. netflix. client. ClientException: Load balancer does not have available server for client: userser
嘿!ONES 新星请看过来|师兄师姐说
2022年上海市安全员C证操作证考试题库模拟考试平台操作
Nat. Commun. | Knowledge integration and decision support for accelerating the discovery of antibiotic resistance genes
路由器实验之serial接口的静态路由配置(补充)
Photoshop如何打开、编辑和导出Webp格式图片的方法
带你初步了解 类和对象 的基本机制
Complete AHK function commands
When V-IF and V-for need to be used at the same time
Force buckle 20 Valid parentheses
What is the highest compound interest insurance product? How much does it cost a year?
Xinsi technology helps Israel visuality systems promote the "left shift" of security
Nacos registry
【玩转华为云】鲲鹏DevKit迁移实战









