class Solution { public: int StrToInt(string str) { int flag,index=0; if(str[0]=='+'){ flag=1; index++; } if(str[0]=='-'){ flag=-1; index++; } int sum=0; for(;index<str.length();index++) { if(!(str[index]>='0'&&str[index]<='9')) return 0; sum=sum*10+(str[index]-'0'); } return sum*flag; } };