第八题

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. ZooKeeper系列(3)--基于ZooKeeper实现主从协作

    基于ZooKeeper实现主从协作 主-从模式的模型中,主要包括三个角色: 主节点:主要负责监视新的节点和任务,分配任务给可用的从节点; 从节点:通过注册自己,确保主节点看到它们可以执行任务,收到主节 ...

  2. kali linux 安装TIM or QQ(CrossOver 安装 QQ)

    需要文件 http://www.crossoverchina.com/xiazai.html dpkg --add-architecture i386 apt-get update apt-get i ...

  3. 将图片写入二进制文件,再从二进制文件还原图片(c++)

    #include "string" #include "iostream" #include "fstream" using namespa ...

  4. 日期格式操作,在oracle和mysql中的实现

    oracle add_months(日期格式值 , 整数n)  当整数n=12时,代表一年,向后推迟一年,若n=-12代表回退一年 如 to_char(add_months(to_date('2018 ...

  5. js滚动监听

    下边代码,是监听滚动条只要移动,下方的返回顶部的div显示与隐藏的代码 ? 1 2 3 4 5 6 7 8 window.onscroll = function () {  var t = docum ...

  6. IO流,字符流

    import java.io.FileReader; public class FileReaderDemo { public static void main(String[] args) thro ...

  7. animation(动画)设置

    1.animation 动画 概念:当您在 @keyframes 中创建动画时,请把它捆绑到某个选择器,否则不会产生动画效果. 通过规定至少以下两项 CSS3 动画属性,即可将动画绑定到选择器: 规定 ...

  8. Python3简单登录接口编写及遇到的问题分享

    1.程序目标 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 2.思路 利用python中的pickle模块,实现用户登录信息(采用dict)和被锁定用户信息(采用list)的存储.所以我预先 ...

  9. golang使用rabbitMQ入门代码

    package main import ( "github.com/streadway/amqp" "log" "time" ) func ...

  10. ubuntu安装cuda、cudnn

    环境: Ubuntu 16.04.4 LTS CUDA:8.0 CUDNN:5.1 CUDA下载:https://developer.nvidia.com/cuda-80-ga2-download-a ...