8. String to Integer (atoi)
来源:互联网 发布:免费视频制作软件知乎 编辑:程序博客网 时间:2024/06/07 19:15
Implement atoi to convert a string to an integer.
public class Solution { public int myAtoi(String str) { str = str.trim(); if(str == null || str.length() == 0) return 0; int res = 0; int index = 0; int op = 1; if(str.charAt(index) == '+') index++; else if(str.charAt(index) == '-'){ index++; op = -1; } for(; index < str.length(); index++){ int tmp = str.charAt(index) - '0'; if(tmp >= 10 || tmp < 0) break; int old = res; res = res * 10 + tmp; if(res / 10 != old){ if(op == 1) return Integer.MAX_VALUE; if(op == -1) return Integer.MIN_VALUE; } } return res*op; }}
0 0
- 8.String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8.String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 8. String to Integer (atoi)
- 学习Unity3D是一件痛并快乐着的事
- Java分割字符串split
- phonegap安装特别慢,一直没有安装结果,这正常吗?
- 外网映射的几种方法
- 深入理解 Session 与 Cookie
- 8. String to Integer (atoi)
- 配置OpenGLES环境的问题
- 找到比一个数大的距离最近的2的n次方的值
- diff/sort/uniq/awk/vi
- iOS 切换视图,求助!!!
- 循环中的闭包
- 【不定期更新】一些简单的Rust程序
- AD使用总结4——PCB天线知识
- Scala快学(3) 数组相关操作