python写算法题:leetcode: 8. String to Integer (atoi)
来源:互联网 发布:2017经济下行 知乎 编辑:程序博客网 时间:2024/06/14 21:01
https://leetcode.com/problems/string-to-integer-atoi/#/description
class Solution(object): def myAtoi(self, str): """ :type str: str :rtype: int """ realstr = "" negative = 1 stage = 0 for s in str: if stage==0: if s in " \t": continue if s == '+': stage=1 continue if s == '-': stage=1 negative=-1 continue if s >= '0' and s<= '9': realstr+=s stage=2 continue break if stage!=0: if s >= '0' and s<= '9': realstr+=s else: break if realstr=="": return 0 res=0 for s in realstr: res=ord(s)-ord('0')+res*10 res=negative*res if(res>2147483647) : return 2147483647 if(res<-2147483648) : return -2147483648 return res
阅读全文
0 0
- python写算法题:leetcode: 8. String to Integer (atoi)
- 8. String to Integer (atoi) Leetcode Python
- 【LeetCode】【Python】8. String to Integer (atoi)
- 【LeetCode with Python】 String to Integer (atoi)
- [LeetCode] String to Integer (atoi) Python
- 【Leetcode】【python】String to Integer (atoi)
- LeetCode算法题目:String to Integer (atoi)
- Leetcode题解(Python): 8. String to Integer (atoi)
- Leetcode 8. String to Integer (atoi) The Solution of Python
- 8. String to Integer (atoi) leetcode算法笔记
- LeetCode OJ算法题(八):String to Integer (atoi)
- LeetCode算法题之String to Integer (atoi)
- [leetcode]经典算法题- String to Integer (atoi)
- LeetCode算法题——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)
- easyui之draggable控件分析,待完善
- cxf和spring的整合出现的问题:javax.xml.ws.soap.SOAPFaultException: Cannot create a secure XMLInputFactory
- 209.m1-banner的自动切换
- python写算法题:leetcode: 7. Reverse Integer
- cxf和spring的整合出现的问题:cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can b
- python写算法题:leetcode: 8. String to Integer (atoi)
- 成长就是从认识到自己的无知而开始的
- 网络请求框架对比
- log4j2 xml配置详解
- 外网访问WordPress时无法加载样式表CSS
- Android View深入浅出
- 微信tinker热更新
- 多线程总结
- 安装idea带破解和创建第一个Maven项目图文详解