Implement atoi to convert a string to an integer.

Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.

Notes: It is intended for this problem to be specified vaguely (ie, no given input specs). You are responsible to gather all the input requirements up front.

 class Solution {
public:
int myAtoi(string str) {
long long cur=;
int num=,i=;
int flag1=,flag2=;
while(str[i]!='\0' && str[i]==' ') i++;
if(str[i]=='-') flag1++,i++;
else if(str[i]=='+') flag2++,i++;
for(; str[i]!='\0'; i++)
{
if(str[i]>='' && str[i]<='')
{
if(flag1==)
{
cur=cur*-(str[i]-'');
if(cur<-) return -;
}
else if(flag1==) cur=-str[i]+'',flag1++;
else
{
cur=cur*+(str[i]-'');
if(cur>) return ;
}
}
else break;
}
num=(int)cur;
return num;
}
};

LeeCode-String to Integer (atoi)的更多相关文章

  1. 【leetcode】String to Integer (atoi)

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

  2. No.008 String to Integer (atoi)

    8. String to Integer (atoi) Total Accepted: 112863 Total Submissions: 825433 Difficulty: Easy Implem ...

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

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

  4. 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 ...

  5. String to Integer (atoi) - 字符串转为整形,atoi 函数(Java )

    String to Integer (atoi) Implement atoi to convert a string to an integer. [函数说明]atoi() 函数会扫描 str 字符 ...

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

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

  7. LeetCode--No.008 String to Integer (atoi)

    8. String to Integer (atoi) Total Accepted: 112863 Total Submissions: 825433 Difficulty: Easy Implem ...

  8. leetcode-algorithms-8 String to Integer (atoi)

    leetcode-algorithms-8 String to Integer (atoi) Implement atoi which converts a string to an integer. ...

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

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

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

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

随机推荐

  1. ApiDemos--&gt;Views-lists-slow adapter学习

    今天来依照apidemos提供的方法来实现slow loading的效果. 简单说下实现方法: 实现ListView.OnScrollListener ,监听到手势滑动的情况,当处于滚动状态时,将新显 ...

  2. POJ 2044 Weather Forecast

    意甲冠军:有一2*2云,而一个4*4范围.在当天密布区必须有雨.有云4招式种类 .期间希望不要下雨,并且一个地方不能有连续7天没下雨. 思路:首先解决一个地方不能有连续7天没下雨的情况,要让地图上的全 ...

  3. In-Cell、On-Cell和OGS全贴合屏幕技术区别

    昨天刚发布的小米3用的是OGS全贴合屏幕技术,包括魅族MX3也是同样的技术,但是iPhone5是In-Cell屏幕技术,什么才是全贴合?它们之间到底有何区别?哪个好?小编今天就来普及一下全贴合屏幕技术 ...

  4. 理解 B*tree index内部结构

    转载请注明出处:http://write.blog.csdn.net/postedit/40589651 Oracle数据库里的B树索引就好象一棵倒长的树.它包括两种类型的数据块:一种是索引分支块,还 ...

  5. Freemarker常用技巧(三)

    freemarker模板解析过程 例如:一个freemarker表达式<body> ${hello} </body>,会被解析成三个部分,分别是<body>${he ...

  6. Linux UDP严重丢包问题的解决

    测试系统在Linux上的性能发现丢包率极为严重,发210000条数据,丢包达110000之巨,丢包率超过50%.同等情形下Windows上测试,仅丢几条数据.形势严峻,必须解决.考虑可能是因为协议栈B ...

  7. Error prompt:“wget: unable to resolve host address”---Solution

    //Situation System prompts that:"wget: unable to resolve host address".   //Analysis   Una ...

  8. spring的xml的property和constructor-arg的解析

    参考文档: http://zzy7182.iteye.com/blog/1153473

  9. C# ZXing.Net生成二维码、识别二维码、生成带Logo的二维码(二)

    1.使用ZXint.Net生成带logo的二维码 /// <summary> /// 生成带Logo的二维码 /// </summary> /// <param name ...

  10. (转)jQuery LigerUI 插件介绍及使用之ligerTree

    一,简介  ligerTree的功能列表: 1,支持本地数据和服务器数据(配置data或者url) 2,支持原生html生成Tree 3,支持动态获取增加/修改/删除节点 4,支持大部分常见的事件 5 ...