国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宜州市| 高陵县| 拉萨市| 双柏县| 峨山| 东源县| 通州区| 醴陵市| 阿拉尔市| 梧州市| 柯坪县| 临漳县| 兰西县| 嘉祥县| 砚山县| 安陆市| 望城县| 吉安县| 旌德县| 迁西县| 龙里县| 象山县| 福泉市| 青海省| 浠水县| 从江县| 博湖县| 秦皇岛市| 揭东县| 固始县| 夏津县| 长沙市| 宜黄县| 桓台县| 宝丰县| 张家川| 康保县| 砀山县| 平和县| 许昌县| 乐平市|