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. hdu 2768

    求最大留下的观众,观众之间存在不能同时满足的关系,就是矛盾关系, 矛盾关系建边,建边是双向的所以最大匹配要/2 还有一种建图的方法:把观众分成两个集合,一个是投留下猫的,一个是投留下狗的 每个集合间没 ...

  2. LeetCode-001 Two Sum

    [题目] Given an array of integers, find two numbers such that they add up to a specific target number. ...

  3. Copy from chromium-dev!

    https://app.yinxiang.com/pub/gguangle0/chromium-dev 做了一些搬运工的活..............

  4. servlet上传文件报错(一)

    1.详细报错例如以下: org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multip ...

  5. C#中T的用法

    之前一直用List<T>这样的泛型,看到过有些参数类型也可以直接用T的,觉得很好用,但是一直用不了,现在才发现原来是少加了<T> public T getdate<T&g ...

  6. 分享:一个基于NPOI的excel导入导出组件(强类型)

    一.引子 新进公司被安排处理系统的数据报表任务——对学生的考试成绩进行统计并能导出到excel.虽然以前也有弄过,但感觉不是很好,所以这次狠下心,多花点时间作个让自己满意的插件. 二.适用领域 因为需 ...

  7. [Web远程wsshd]CentOS6.4搭建配置wssh

    wssh 是一个 SSH 到 WebSockets 的桥,可以让你通过 HTTP 调用远程服务器的 SHELL 命令.wssh 可以让我们通过 HTTP 来调用远程的一个 shell,也就是说我们可以 ...

  8. Demo 示例控制输入光标位置

    <!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <meta name="aut ...

  9. Docker容器的数据管理

    Docker容器的数据管理 Docker容器的数据管理 什么是数据卷(Data Volume)? 数据卷是经过特殊设计的目录,可以绕过联合文件系统(UFS),为一个或者多个容器提供访问 数据卷设计的目 ...

  10. zookeeper参考

        ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护.名字服务.分布式同步.组服务等.     我需要运行几个 ...