LeetCode-8-String-to-Integer (atoi) 细节题
来源:互联网 发布:centos下安装jdk1.8 编辑:程序博客网 时间:2024/06/07 03:24
很无聊的题目,注意一下要求的各种边界条件,仔细读题就好,不读题免不了WA几发
class Solution(object): def myAtoi(self, str): """ :type str: str :rtype: int """ if(str==""):return 0 Len=len(str) flag=1 pl=0 pr=Len for i in range(Len): if str[i]!=" ": if str[i]=='+': pl=i+1 break elif str[i]=='-': pl=i+1 flag=-1 break elif str[i]>='0' and str[i]<='9': pl=i break else: return 0 if not(pl<Len and str[pl]>='0' and str[pl]<='9'): return 0 for i in range(pl,Len): if str[i]<'0' or str[i]>'9': pr=i; break; ans=flag*int(str[pl:pr]) if ans<-2147483648: return -2147483648 if ans>2147483647: return 2147483647 return ans
阅读全文
1 0
- LeetCode-8-String-to-Integer (atoi) 细节题
- LeetCode 8 - String to Integer (atoi)
- [LeetCode 8] String to Integer (atoi)
- leetcode 8STRING TO INTEGER (ATOI)
- Leetcode【8】:String to Integer(atoi)
- [leetcode 8] String to Integer (atoi)
- LeetCode(8) String To Integer(atoi)
- [leetcode 8] String to Integer (atoi)
- LeetCode 8:《String to Integer (atoi) 》
- leetcode.8---------------String to Integer (atoi)
- leetCode #8 String to Integer (atoi)
- [LeetCode Java] 8 String to Integer (atoi)
- leetcode 8 String to Integer (atoi)
- leetcode-8 String to Integer(atoi)
- LeetCode 8 String to Integer (atoi)
- LeetCode(8)String to Integer (atoi)
- LeetCode 8 - String to Integer (atoi)
- leetcode #8 String to Integer (atoi)
- JavaScript 书写方式与注释
- MySQL 5.7 (3复制)
- Unity 3D项目问题笔记 //02_制作 2D UI相关问题
- navicat远程连接mysql,2003 can't connect to mysql server on 10038
- Linux(二):巧用分号在命令行执行逻辑判断语句
- LeetCode-8-String-to-Integer (atoi) 细节题
- Coming Back
- JS变量与命名规范
- 1.计算机组成原理笔记一计算机系统概论
- Cannot load underlying module for 'SnapKit' 通过Cocoapods导入SnapKit(大坑!!!)
- js 导出 excel 身份证号等长数字变成科学计数法
- VIM自动补全神器 — YouCompleteMe 安装全教程
- 在本地maven仓库添加自定义的jar包
- 关于WebService的第三方基础学习