第八题

class Solution {
public:
int myAtoi(string str) {
int i = ;
long sum = ;
int sign = ;
while(str[i] == ' ')i++;
if (str[i] == '-'|| str[i] == '+')
{
if(str[i] == '-') sign = -;
i++;
}
while(str[i]<='' && str[i]>='')
{
if(sum>=INT_MAX) break;
sum = sum * + str[i++] - '';
}
sum*=sign;
if(sum>=INT_MAX)return INT_MAX;
if(sum<=INT_MIN)return INT_MIN;
return sum;
}
};

leetcode个人题解——#8 string to integer的更多相关文章

  1. 《LeetBook》leetcode题解(8): String to Integer (atoi) [E]——正负号处理

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

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

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

  3. leetcode第八题 String to Integer (atoi) (java)

    String to Integer (atoi) time=272ms   accepted 需考虑各种可能出现的情况 public class Solution { public int atoi( ...

  4. LeetCode【8】. String to Integer (atoi) --java实现

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

  5. LeetCode题解 #8 String to Integer (atoi)

    又是一道恶心的简单题. 一开始没想到这么多情况的,幸好LeetCode是个很人性化的oj,能让你知道你在哪个case上错了,否则一辈子都过不了. 考虑不周到只能一个个补了. 列举一下恶心的case / ...

  6. leetcode第八题--String to Integer (atoi)

    Problem: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible inp ...

  7. [leetcode]经典算法题- String to Integer (atoi)

    题目描述: 把字符串转化为整数值 原文描述: Implement atoi to convert a string to an integer. Hint: Carefully consider al ...

  8. LeetCode(8)String to Integer (atoi)

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

  9. 【leetcode❤python】 8. String to Integer (atoi)

    #-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...

随机推荐

  1. linuxc - entos 7.3 开放端口并对外开放

    1. 查看已打开的端口 # netstat -anp 2. 查看想开的端口是否已开 # firewall-cmd --query-port=666/tcp 若此提示 FirewallD is not ...

  2. mysql 使用order by

    1.mysql 使用order by field() 自定义排序 order by field(value,str1,str2,str3,str4......strn) 例如:select * fro ...

  3. ObjC之RunTime(下)

    之前通过学习官方文档对runtime有了初步的认识,接下来就要研究学习runtime到底能用在哪些地方,能如何改进我们的程序. 本文也可以从icocoa浏览. Swizzling Swizzling可 ...

  4. github常见操作和常见错误

    配置git的时候会使用git config,三种配置分别为git config.git config --global.git config --system. 它们之前的优先级为(由高到低):git ...

  5. 『ACM C++』 PTA 天梯赛练习集L1 | 048-49

    今日刷题048-049 ------------------------------------------------L1-048---------------------------------- ...

  6. show status 查看各种状态

    要查看MySQL运行状态,要优化MySQL运行效率都少不了要运行show status查看各种状态,下面是参考官方文档及网上资料整理出来的中文详细解释: 如有问题,欢迎指正 状态名 作用域 详细解释 ...

  7. ElasticSearch 集群安装,简单使用

    http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html https://gith ...

  8. 环境变量Path简介

    更多详细专业的详解,请参见:http://www.cnblogs.com/sunada2005/articles/2725277.html 什么是Path变量: PATH环境变量.作用是指定命令搜索路 ...

  9. 将 List<Obj> 集合, 导出至 Excel

    主代码在这:http://www.codeproject.com/Articles/120480/Export-to-Excel-Functionality-in-WPF-DataGrid 黑人老外写 ...

  10. 【转】Odoo 学习之:constrains装饰

    constrains装饰用于对字段进行限制 应用举例: 定义列: age = fields.Integer(string="age") 方法: @api.constrains('a ...