标签:lse wing class als ios false amp div min
1 static int wing=[]() 2 { 3 std::ios::sync_with_stdio(false); 4 cin.tie(NULL); 5 return 0; 6 }(); 7 8 class Solution 9 { 10 public: 11 int myAtoi(string str) 12 { 13 int flag=1,i=0,base=0; 14 while(str[i]==‘ ‘) 15 i++; 16 if(str[i]==‘-‘||str[i]==‘+‘) 17 { 18 flag= (str[i]==‘-‘)?-1:1; 19 i++; 20 } 21 while(isdigit(str[i])) 22 { 23 if(base>INT_MAX/10||(base==INT_MAX/10&&str[i]-‘0‘>7)) 24 return flag==1? INT_MAX:INT_MIN; 25 base=10*base+(str[i++]-‘0‘); 26 } 27 return base*flag; 28 } 29 };
边扫描边转换,同时判定溢出。
标签:lse wing class als ios false amp div min
原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9259982.html