当前位置:网站首页>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
边栏推荐
- Cv2.fillpoly coco annotator segment coordinate conversion to mask image
- 数据库全量SQL分析与审计系统性能优化之旅
- PHP 开发环境搭建及数据库增删改查
- Multithreading Foundation (XI) -- prevent CPU from occupying 100%
- LeetCode个人题解(剑指offer3-5)3.数组中重复的数字,4.二维数组中的查找,5.替换空格
- Trunet: short videos generation from long videos via story preserving truncation (thesis translation)
- leetcode 278. First wrong version
- LeetCode-1445. Apples and oranges
- Nodemon cannot load the file c:\users\administrator\appdata\roaming\npm\nodemon PS1, because script execution is prohibited in this system
- Computer composition and design work06 - based on MIPS
猜你喜欢

How to build your own website (using the pagoda panel)

PHP read / write cookie

Qt-- realize TCP communication

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

leetcode 278. First wrong version

It only takes 10 minutes to understand the underlying principle of NiO

Multithreading (4) -- no lock (3) -- longadder source code

AI作业ch8

An error occurred while downloading the remote file The errormessage

2021 RoboCom 世界机器人开发者大赛-本科组(初赛)
随机推荐
Leetcode personal question solution (Sword finger offer3-5) 3 Duplicate number in array, 4 Find in 2D array, 5 Replace spaces
leetcode 300. Longest increasing subsequence
上传文件(post表单提交form-data)
LeetCode-1303. Team size
SQL 注入读写文件
LeetCode-1576. Replace all question marks
Video fire detection based on Gaussian mixture model and multi-color
Delete the duplicate items in the ordered array -- force deduction question 26 (simple)
[word] word 2010 recording macro batch replacing paragraph marks in the selected text
Excel VBA opens a file that begins with the specified character
platform driver
Computer composition and design work06 —— 基于MIPS
The principle of SQL injection is to build sqli labs, and SQL injection is simple and practical
The seventh day of June training - hash table
Leetcode January 13 daily question 747 At least twice the maximum number of other numbers
Computer composition and design work06 - based on MIPS
2021 robocom world robot developer competition - undergraduate group (Preliminary)
Qt-- realize TCP communication
Solution: unsatisfieddependencyexception: error creating bean with name 'authaspect':
Redis distributed lock