[Leetcode] String to Integer (atoi)
来源:互联网 发布:淘宝客推广中pid是什么 编辑:程序博客网 时间:2024/05/22 06:13
C语言版本:
int myAtoi(char* str) { int i=0,flag=1; long long ans=0; if(str[i]=='\0'||strlen(str)==1&&(!(str[i]<='9'&&str[i]>='0')))//特殊情况 return 0; while(str[i]==' ')//去除空格 i++; if(!(str[i]<='9'&&str[i]>='0'||str[i]=='-'||str[i]=='+'))//特殊字符直接结束 return 0; if(str[i]=='-'||str[i]=='+'){ flag=str[i++]=='-'?0:1; }//取正负 for(;str[i]!='\0';i++){ if(!(str[i]<='9'&&str[i]>='0'))//特殊字符结束读取 break; else if(str[i+1]<='9'&&str[i+1]>='0')//字符串转化为数字 ans=(ans+str[i]-'0')*10; else ans+=str[i]-'0'; if(ans>INT_MAX)//溢出检测 return flag>0?INT_MAX:INT_MIN; } return flag>0?ans:-ans;}
0 0
- LeetCode:String to Integer (atoi)
- LeetCode: String to Integer (atoi)
- LeetCode String to Integer(atoi)
- LeetCode :String to Integer (atoi)
- Leetcode: String to Integer (atoi)
- Leetcode : String to Integer (atoi)
- 【leetcode】String to Integer (atoi)
- [LeetCode]String to Integer (atoi)
- LeetCode-String to Integer (atoi)
- [leetcode] String to Integer (atoi)
- LeetCode - String to Integer (atoi)
- 【leetcode】String to Integer (atoi)
- LeetCode - String to Integer (atoi)
- LeetCode: String to Integer (atoi)
- Leetcode: String to Integer (atoi)
- [LeetCode] String to Integer (atoi)
- leetcode String to Integer (atoi)
- [LeetCode]String to Integer (atoi)
- struts 接收参数(通过model接收)
- 生产者消费者
- 发布Qt5程序时图标的设置
- mac系统启动startup.sh tomcat启动失败问题!
- BZOJ3143: [Hnoi2013]游走
- [Leetcode] String to Integer (atoi)
- gcc编译器 工程管理器
- MyEclipse 快捷键
- [BZOJ3997][TJOI2016]组合数学 平面图
- PHP底层的运行机制与原理
- 散列入门(3)----pat-b1033. 旧键盘打字(20)
- 怎样处理服务器负载量过大
- 开灯问题
- Grid Growing Clustering Algorithm