leetcode-8
来源:互联网 发布:朝鲜奢侈生活知乎 编辑:程序博客网 时间:2024/06/05 03:28
题目:
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.
代码:
- public int myAtoi(String str) { //code 8
if(str.length() == 0 || str == null)
return 0;
str = str.trim();
int p = 0;
double res = 0;
int len = str.length();
while(str.charAt(p) == ' ' || str.charAt(p) == '\t')
p++;
boolean negflag = false;
if(str.charAt(p) == '+' || str.charAt(p) == '-')
negflag = (str.charAt(p++) == '-');
while( p < len && (str.charAt(p) >= '0' && str.charAt(p) <= '9') ){
res = res*10 + (str.charAt(p++) - '0');
}
res = negflag?-res:res;
if(res > Integer.MAX_VALUE)
return Integer.MAX_VALUE;
if(res < Integer.MIN_VALUE)
return Integer.MIN_VALUE;
return (int)res;
}
}
1 0
- leetcode 8
- leetcode-8
- leetcode 8
- Leetcode--8
- LeetCode(8)
- leetcode 8
- LeetCode(8)StringToInteger
- [LeetCode] Reverse Integer [8]
- Leetcode--easy系列8
- leetcode #8 atoi
- leetcode第8题
- Leetcode(8)-medium2
- leetcode 8 atoi
- Leetcode no. 8
- leetcode试题总结<8>
- 【Leetcode】UTF-8 Validation
- LeetCode OJ(8)
- Leetcode #8 Solution
- css border那点事
- DirectFB的架构介绍
- win7常用cmd命令
- 345. Reverse Vowels of a String
- SQL Server 2008安装报错:The specified credentials for the sql server service are not valid
- leetcode-8
- 140_自定义ViewPager
- jdbc,if(res.next)判断结果失败
- NOJ——1508火烧赤壁2(并查集+启发式合并+逆序加边)
- 141_自定义Transformer
- Java操作Excel文件以及将xls/xlsx转为csv文件
- Spark Streaming源码解读之Job动态生成和深度思考
- 最新android APP框架介绍
- Octave 线性代数 行列式 2