leetcode之atoi
来源:互联网 发布:淘宝店铺宝箱怎么设置 编辑:程序博客网 时间:2024/05/16 01:09
class Solution {
public:
int atoi(const char *str) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if (str == NULL) {
return 0;
}
bool isNegtive = false;
char* start = const_cast<char*>( str);
int len = strlen(str);
char* end = start+len-1;
if (*start == '-') {
isNegtive = true;
start++;
}
if (*start=='+') {
isNegtive = false;
start++;
}
int res = 0;
bool first = true;
while (start <= end) {
if (first&&*start=='0') {
start++;
}
if (isdigit(*start)) {
first = false;
res = res*10+(*start-'0');
}
start++;
}
if (isNegtive) {
res = 0-res;
}
return res;
}
};
public:
int atoi(const char *str) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if (str == NULL) {
return 0;
}
bool isNegtive = false;
char* start = const_cast<char*>( str);
int len = strlen(str);
char* end = start+len-1;
if (*start == '-') {
isNegtive = true;
start++;
}
if (*start=='+') {
isNegtive = false;
start++;
}
int res = 0;
bool first = true;
while (start <= end) {
if (first&&*start=='0') {
start++;
}
if (isdigit(*start)) {
first = false;
res = res*10+(*start-'0');
}
start++;
}
if (isNegtive) {
res = 0-res;
}
return res;
}
};
- leetcode之atoi
- leetcode之atoi() in java
- LeetCode(atoi)实现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之8_String to Integer (atoi)
- LeetCode之8----String to Integer (atoi)
- LeetCode之8,著名的atoi
- LeetCode 之 String to Integer (atoi)
- [Leetcode] Atoi
- Leetcode: atoi
- [LeetCode] atoi
- LeetCode Atoi
- c/c++里的 堆区 栈区 静态区 文字常量区 程序代码区
- 2013豆瓣校园招聘研发类笔试题
- VC之获取计算机网卡mac地址
- IS7配置Gzip压缩
- poj 2063 Investment 完全背包问题
- leetcode之atoi
- PE行业的软件和解决方案
- android 在你的UI中显示Bitmap - 开发文档翻译
- C 语言中的各个段
- Clob,Blob,InputStream,byte 互转
- JS
- 哈希表——开放定址法
- 手机安全卫士开发系列(7)——知识点整理(1)
- android 自定义ImageView实现图片手势滑动,多点触摸放大缩小效果