当前位置:网站首页>Leetcode: Sword finger offer 67 Convert string to integer [simulation + segmentation + discussion]
Leetcode: Sword finger offer 67 Convert string to integer [simulation + segmentation + discussion]
2022-06-12 06:36:00 【Review of the white speed Dragon King】

analysis
A discussion about illegality
A discussion of the first positive and negative
A discussion of significant numbers
A discussion about converting to results
Discussion on Cross-border
Ac code
class Solution:
def strToInt(self, str: str) -> int:
MIN = - 2 ** 31
MAX = 2 ** 31 - 1
str = str.strip()
if len(str) == 0 or (str[0].isdigit() is False and str[0] not in ('+', '-')):
return 0
mul = 1
if str[0] == '+':
str = str[1:]
elif str[0] == '-':
mul = -1
str = str[1:]
digit = ''
i = 0
n = len(str)
while i < n:
if str[i].isdigit():
digit += str[i]
i += 1
else:
break
if digit == '':
return 0
digit = int(digit)
digit *= mul
if digit < MIN:
return MIN
elif digit > MAX:
return MAX
else:
return digit
summary
Classification routines and simulation
边栏推荐
- leetcode 704. Binary search
- Single channel picture reading
- QT--实现TCP通信
- Multithreading (4) -- no lock (3) -- longadder source code
- leetcode:剑指 Offer 63. 股票的最大利润【记录前缀最小和 or 无脑线段树】
- Deep and detailed analysis of PHP one sentence Trojan horse
- Apache poi 导入导出Excel文件
- PDF. JS help file
- Zip and Items() difference
- Leetcode sword finger offer (Second Edition) complete version of personal questions
猜你喜欢

VSCode常用插件

Tomato learning notes -seq2seq

Redis configuration (IV) -- cluster

Solution: unsatisfieddependencyexception: error creating bean with name 'authaspect':

SQL 注入读写文件

PHP一句话木马深度详细剖析

Opencv_ 100 questions_ Chapter V (21-25)

Codeforces Round #793 (Div. 2) A B C

LeetCode-1490. Clone n-ary tree

Leetcode January 10 daily question 306 Additive number
随机推荐
CONDA create use virtual environment
Highlight detection with pairwise deep ranking for first person video summary (thesis translation)
LeetCode-剑指Offer(第二版)个人题解完整版
Trunet: short videos generation from long videos via story preserving truncation (thesis translation)
Touch screen setting for win7 system dual screen extended display
leetcode 278. First wrong version
LeetCode-1078. Bigram participle
leetcode:剑指 Offer 67. 把字符串转换成整数【模拟 + 分割 +讨论】
SQL注入——联合查询union
platform driver
LeetCode-1445. Apples and oranges
集合判断存在交集
Redis configuration (III) -- master-slave replication
Automatic modeling of Interchange
Qt-- realize TCP communication
LeetCode-1576. Replace all question marks
GET 和 POST 的区别及留言板代码实现
Apache POI import export excel file
Use ms17-010 Eternal Blue vulnerability to infiltrate win7 and establish a permanent back door
Apache poi 导入导出Excel文件