[C++]Leetcode #8 atoi()
来源:互联网 发布:淘宝举报假冒及盗版 编辑:程序博客网 时间:2024/05/16 10:46
class Solution {public: int myAtoi(string str) { int n=str.length(); int number[n]; int j=-1, flag=0; for(int i=0;i<n;i++) { if(str[i]=='+' || str[i]=='-') { if(isdigit(str[i+1])==false) { return 0; } } if(isdigit(str[i])==true) { j=j+1; number[j]=int(str[i]-'0'); if(i>=1) { if(str[i-1]=='+') { flag=0; } else if(str[i-1]=='-') { flag=1; } else if(str[i-1]!=' '&&isdigit(str[i-1])==false){ return 0 ; } }if(i>=2){if((str[i-1]=='+')&&(str[i-2]=='-')){return 0;}if((str[i-1]=='-')&&(str[i-2]=='+')){return 0;}} if(i+1<n){ if(isdigit(str[i+1])==false) { break; } } } } long long result=0; for(int k=j;k>=0;k--) { unsigned long x=number[k]*pow(10,j-k); if(flag==0){ result=result+x; } else{ result=result-x; } if(result>=INT_MAX) { return INT_MAX; } if(result<=INT_MIN) { return INT_MIN; } } return result; }};
0 0
- [C++]Leetcode #8 atoi()
- LeetCode 8 String to Integer (atoi) (C,C++,Java,Python)
- LeetCode 8 String to Integer (atoi) (C,C++,Java,Python)
- leetcode #8 atoi
- leetcode 8 atoi
- LeetCode (8) String to Integer (atoi) C语言程序
- [C++]LeetCode: 24 String to Integer (atoi)
- 【leetcode c++】08 String to Integer (atoi)
- Leetcode c语言-String to Integer (atoi)
- leetcode--8--实现atoi函数
- LeetCode(atoi)实现atoi
- [Leetcode] Atoi
- Leetcode: atoi
- [LeetCode] atoi
- LeetCode Atoi
- leetcode atoi
- Leetcode--atoi
- LeetCode-Atoi
- 【LeetCode】 111. Minimum Depth of Binary Tree
- JavaEE中的MVC(五)定制Struts——Action跳转JSP
- React-Native从入门到放弃(一)准备篇
- React-Native从入门到放弃(二)
- Leetcode 118. Pascal's Triangle
- [C++]Leetcode #8 atoi()
- date命令--Linux命令应用大词典729个命令解读
- compress命令--Linux命令应用大词典729个命令解读
- vgscan命令--Linux命令应用大词典729个命令解读
- sysctl命令--Linux命令应用大词典729个命令解读
- logout命令--Linux命令应用大词典729个命令解读
- how to change Scheme name
- nisdomainname命令--Linux命令应用大词典729个命令解读
- Could not open Hibernate Session for transaction