class Solution(object):
def myAtoi(self, str):
"""
:type str: str
:rtype: int
"""
intMax=2147483647
intMin=-2147483648
str=str.strip()
strLen = len(str)
if strLen <= 0:
return 0 bolNegative = False
tmp = str[0]
start=0 if tmp == '-' or tmp == '+':
start=1 if tmp == '-':
bolNegative = True
rs=0
for i in range(start, strLen ):
tmp = str[i]
if tmp >= '' and tmp <= '':
rs=rs*10+int(tmp)
elif tmp == '-' or tmp == '+':
return 0
else:
break
intTmp = rs
if bolNegative:
intTmp*=-1
if intTmp > intMax:
return intMax
if intTmp < intMin:
return intMin
return intTmp

leetcode String to Integer (atoi) python的更多相关文章

  1. LeetCode: String to Integer (atoi) 解题报告

    String to Integer (atoi) Implement atoi to convert a string to an integer. Hint: Carefully consider ...

  2. [LeetCode] String to Integer (atoi) 字符串转为整数

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  3. [Leetcode] String to integer atoi 字符串转换成整数

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  4. [LeetCode] String to Integer (atoi) 字符串

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  5. [Leetcode]String to Integer (atoi) 简易实现方法

    刚看到题就想用数组做,发现大多数解也是用数组做的,突然看到一个清新脱俗的解法: int atoi(const char *str) { ; int n; string s(str); istrings ...

  6. [LeetCode]String to Integer (atoi)

    题意:字符串转正数 原题来自:https://leetcode.com/problems/string-to-integer-atoi/ 分析: <程序员面试宝典>上出现的面试题,主要是考 ...

  7. leetcode day6 -- String to Integer (atoi) &amp;&amp; Best Time to Buy and Sell Stock I II III

    1.  String to Integer (atoi) Implement atoi to convert a string to an integer. Hint: Carefully con ...

  8. Kotlin实现LeetCode算法题之String to Integer (atoi)

    题目String to Integer (atoi)(难度Medium) 大意是找出给定字串开头部分的整型数值,忽略开头的空格,注意符号,对超出Integer的数做取边界值处理. 方案1 class ...

  9. Leetcode 8. String to Integer (atoi) atoi函数实现 (字符串)

    Leetcode 8. String to Integer (atoi) atoi函数实现 (字符串) 题目描述 实现atoi函数,将一个字符串转化为数字 测试样例 Input: "42&q ...

随机推荐

  1. SQL整理4

    --====================简单增删改===========--查看学生表的全部数据select * from studio   --插入一个新的学生信息insert into stu ...

  2. 文件和文件夹权限-Win7公共盘中出现大量临时文件

    公司中有一个文件服务器,给不同部门和员工设置了不同的权限,最近有员工(没有修改权限,有读取及执行,读取,写入)反映在公共盘上修改文件的时候会产生大量的临时文件,添加上修改权限之后就可以了,然后被同事问 ...

  3. workspace & subProject & target

    workspace & subProject & target http://blog.itpub.net/12231606/viewspace-1079867/ 最近新入一个项目组, ...

  4. QF——OC中的SEL类型和Block

    @selector(): 可以理解@selector()就是取类方法的编号,他的基本行为类似于C语言中的函数指针(指向函数的指针).它们通过传递方法的地址(或编号)来实现把方法当做参数的效果. 不过在 ...

  5. ajax防止重复提交请求1

    ajax防止重复提交请求 A. 独占型提交 只允许同时存在一次提交操作,并且直到本次提交完成才能进行下一次提交. module.submit = function() {   if (this.pro ...

  6. 关于RSA加密

    RSA算法是一种非对称密码算法,所谓非对称,就是指该算法需要一对密钥,使用其中一个加密,则需要用另一个才能解密. RSA的算法涉及三个参数,n.e1.e2. 其中,n是两个大质数p.q的积,n的二进制 ...

  7. windows环境中mysql忘记root密码的解决办法

    原文地址:http://www.cnblogs.com/linuxnotes/archive/2013/03/09/2951101.html windows下重置Mysql Root密码的方法mysq ...

  8. MyBitis(iBitis)系列随笔之五:多表(一对多关联查询)

    MyBitis(iBitis)系列随笔之一:MyBitis入门实例 MyBitis(iBitis)系列随笔之二:类型别名(typeAliases)与表-对象映射(ORM) MyBitis(iBitis ...

  9. CSV 客座文章系列:KGroup 通过 Windows Azure 将 Qoob 内容管理发布到云中

    编辑人员注释: 今天这篇文章由 KGroup 首席软件架构师兼研发部主管 Jody Donetti 与 KGroup 技术总监 Simone Procopio 共同撰写,介绍了 KGroup 如何使用 ...

  10. uva 10129 poj 1386 hdu 1116 zoj 2016 play on words

    //本来是想练一下欧拉回路的,结果紫书上那题是大水题!!!!! 题意:给出n个单词,是否可以把单词排列成每个单词的第一个字母和上一个单词的最后一个字母相同 解:欧拉通路存在=底图联通+初度!=入度的点 ...