File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -3,31 +3,31 @@ class Solution {
33 int StrToInt (string str) {
44 int res = 0 , bndry = INT_MAX / 10 ;
55 int i = 0 , sign = 1 , length = str.size ();
6- if (length == 0 ) {
6+ if (length == 0 ) {
77 return 0 ;
88 }
99 // 删除首部空格
10- while (str[i] == ' ' ){
11- if (++i == length) {
10+ while (str[i] == ' ' ) {
11+ if (++i == length) {
1212 return 0 ;
1313 }
1414 }
15- // 若有负号则标识符号位
16- if (str[i] == ' -' ) {
15+ // 若有负号则标识符号位
16+ if (str[i] == ' -' ) {
1717 sign = -1 ;
1818 }
19- if (str[i] == ' -' || str[i] == ' +' ) {
19+ if (str[i] == ' -' || str[i] == ' +' ) {
2020 i++;
2121 }
22- for (int j = i; j < length; j++) {
23- if (str[j] < ' 0' || str[j] > ' 9' ) {
22+ for (int j = i; j < length; j++) {
23+ if (str[j] < ' 0' || str[j] > ' 9' ) {
2424 break ;
2525 }
26- // res>214748364越界;res=214748364且str[j] > '7'越界
27- if (res > bndry || res == bndry && str[j] > ' 7' ){
26+ // res>214748364越界;res=214748364且str[j] > '7'越界
27+ if (res > bndry || res == bndry && str[j] > ' 7' ) {
2828 return sign == 1 ? INT_MAX : INT_MIN;
2929 }
30- // 从左向右遍历数字并更新结果
30+ // 从左向右遍历数字并更新结果
3131 res = res * 10 + (str[j] - ' 0' );
3232 }
3333 return sign * res;
You can’t perform that action at this time.
0 commit comments