Leetcode 8. String to Integer (atoi)
来源:互联网 发布:java界面编程在哪 编辑:程序博客网 时间:2024/06/10 02:28
题目:Implement atoi to convert a string to an integer.
思路:编写相应规则即可.
import ctypes
class Solution(object):
def myAtoi(self, str):
"""
:type str: str
:rtype: int
"""
intMax=2147483647
intMin=-2147483648
str = str.strip()
s = '';f = True
for i in str:
if f and i=='-':f=False;s+=i;continue
if f and i=='+':f=False;continue
if '9'>=i>='0':
s+=i
else:break
try:
a = int(s)
if a>intMax:return intMax
if a<intMin:return intMin
return a
except:
return 0
0 0
- [LeetCode]8. String to Integer (atoi)
- LeetCode 8. String to Integer (atoi)
- 8. String to Integer (atoi) Leetcode Python
- 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 OJ> 8. String to Integer (atoi)
- leetCode 8. String to Integer (atoi)
- 8. String to Integer (atoi) LeetCode
- leetcode 8. String to Integer (atoi)
- leetcode 8. String to Integer (atoi)
- LeetCode OJ 8.String to Integer (atoi)
- Leetcode ☞ 8. String to Integer (atoi)
- 8. String to Integer (atoi) ---Leetcode
- leetcode 8. String to Integer (atoi)
- Leetcode: 8. String to Integer (atoi)(JAVA)
- 2017年牛客网校招模拟二
- CSS3自定义滚动条样式 -webkit-scrollbar原文地址:http://www.xuanfengge.com/css3-webkit-scrollbar.html
- 二维数组中的查找
- spark进阶(五)
- [编程题] 有趣的数字
- Leetcode 8. String to Integer (atoi)
- Java模拟面试题
- 缓存加载 新思路 localStorage
- 常用的代理设置
- 完数
- poj1463树形动归
- React.jsDOM获取方式
- 浅谈图形界面引擎开发
- 【图解】Windows系统搭建Android开发环境