LeetCode 008
来源:互联网 发布:windows商城 编辑:程序博客网 时间:2024/04/28 18:45
String to Integer (atoi)
Implement atoi to convert a string to an integer.
/************************************************************************* > File Name: LeetCode8.c > Author: Juntaran > Mail: Jacinthmail@gmail.com > Created Time: 2016年04月24日 星期日 15时51分05秒 ************************************************************************/ /************************************************************************* Implement atoi to convert a string to an integer. ************************************************************************/ #include <stdio.h>#include <limits.h>int myAtoi(char* str) { int flag = 1; long sum = 0; while( *str == ' ' ){ str++; } if ( *str == '+' || *str == '-' ){ flag = (*str++ == '+' ? 1 : -1 ); } while( isdigit(*str) && sum < INT_MAX ){ sum = 10*sum + (*str++ - '0'); } if( flag == 1 ){ sum = sum > INT_MAX ? INT_MAX : sum; printf("%d\n",sum); return sum; }else{ sum = (sum *= flag) < INT_MIN ? INT_MIN : sum; printf("%d\n",sum); return sum; }}int main(){ char* str = "-100.ab"; myAtoi(str);}
0 0
- LeetCode 008
- LeetCode: 008-Contains Duplicate
- LeetCode——008
- LeetCode 008 StringToInteger(atoi)
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- JAVA中的File类,I/O流基础
- 服务器之新手入门
- Swift3.0 / swift2.3中dispatch_group的使用
- AJAX笔记-基本使用
- shell 笔记
- LeetCode 008
- protobuf的安装和使用
- 深入浅出的理解框架(Struts2、Hibernate、Spring)与 MVC 设计模式
- Hive本地配置方案(内嵌Derby数据库)
- LeetCode 28. Implement strStr()
- iOS开发系列--Objective-C之协议、代码块、分类
- 让你的MacBook不需要插件就能支持NTFS读写
- Spring MVC 解决 Could not write JSON: No serializer found for class java.lang.Object
- java小技巧之TabelModel;文件选择器;时间属性设置