国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

LeetCode 8. String to Integer (atoi)

2019-11-08 02:02:38
字體:
來源:轉載
供稿:網友

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.

Update (2015-02-10): The signature of the C++ function had been updated. If you still see your function signature accepts a const char * argument, please click the reload button to reset your code definition.

程序代碼:

int myAtoi(char* str) { char *p = str; int flag = 1; while(*p==' ') p++; if(*p=='-'||*p=='+') { flag = 1-2*(*p=='-'); p++; } int sum = 0; while(*p>='0'&&*p<='9') { if(sum>INT_MAX/10||(sum==INT_MAX/10&&*p-'0'>7)) { if(flag==-1) return INT_MIN; else return INT_MAX; } sum = sum *10 +*p-'0'; p++; } return sum*flag;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 越西县| 渝北区| 镇康县| 车险| 长汀县| 旅游| 丹巴县| 噶尔县| 惠州市| 酒泉市| 永济市| 台南县| 怀安县| 蛟河市| 准格尔旗| 东港市| 长治市| 翁源县| 孙吴县| 延长县| 罗甸县| 奉新县| 射洪县| 京山县| 克拉玛依市| 乌苏市| 乾安县| 新河县| 如东县| 台山市| 惠安县| 广饶县| 江津市| 沅陵县| 宁远县| 汉中市| 盐津县| 石阡县| 台东市| 银川市| 翼城县|