当前位置:网站首页>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
边栏推荐
- 六月集训 第二天——字符串
- Nodemon cannot load the file c:\users\administrator\appdata\roaming\npm\nodemon PS1, because script execution is prohibited in this system
- LeetCode-884. Unusual words in two sentences
- platform driver
- C language pointer
- PDF. js FAQs
- Tomato learning notes -seq2seq
- android studio 利用数据库实现登录注册界面功能
- Video summary with long short term memory
- Computer composition and design work05 ——fifth verson
猜你喜欢

(14)Blender源码分析之闪屏窗口显示软件版本号

Multithreading (2) -- pipeline (2) -- synchronized underlying monitor, lightweight, biased lock, lock inflation

Leetcode January 13 daily question 747 At least twice the maximum number of other numbers

Jetson TX2 machine brushing jetpack4.2 (self test successful version)

PHP read / write cookie

Qt-- realize TCP communication

Reentrantlock underlying AQS source code analysis

Are you still using like+% for MySQL fuzzy query?

SQL 注入读写文件

Tips for using the potplayer video player
随机推荐
torch在高版本训练的模型在低版本中使用报错
ConVIRT论文详解(医疗图片)
Delete the duplicate items in the ordered array -- force deduction question 26 (simple)
2021 robocom world robot developer competition - undergraduate group (Preliminary)
leetcode:剑指 Offer 60. n个骰子的点数【数学 + 层次dp + 累计贡献】
Video based fire smoke detection using robust AdaBoost
Upload file (post form submission form data)
LeetCode个人题解(剑指offer3-5)3.数组中重复的数字,4.二维数组中的查找,5.替换空格
LeetCode-884. Unusual words in two sentences
An error occurred while downloading the remote file The errormessage
Leetcode sword finger offer (Second Edition) complete version of personal questions
SQL language
platform driver
Excel VBA opens a file that begins with the specified character
Torch models trained in higher versions report errors in lower versions
Leetcode January 12 daily question 334 Increasing ternary subsequence
六月集训 第九日——位运算
Trunet: short videos generation from long videos via story preserving truncation (thesis translation)
Tomato learning notes-stm32 SPI introduction and Tim synchronization
Leetcode January 10 daily question 306 Additive number