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 @@ -151,31 +151,31 @@ public:
151
151
int StrToInt(string str) {
152
152
int res = 0, bndry = INT_MAX / 10;
153
153
int i = 0, sign = 1, length = str.size();
154
- if(length == 0) {
154
+ if (length == 0) {
155
155
return 0;
156
156
}
157
157
// 删除首部空格
158
- while(str[ i] == ' '){
159
- if(++i == length) {
158
+ while (str[ i] == ' ') {
159
+ if (++i == length) {
160
160
return 0;
161
161
}
162
162
}
163
- //若有负号则标识符号位
164
- if(str[ i] == '-') {
163
+ // 若有负号则标识符号位
164
+ if (str[ i] == '-') {
165
165
sign = -1;
166
166
}
167
- if(str[ i] == '-' || str[ i] == '+') {
167
+ if (str[ i] == '-' || str[ i] == '+') {
168
168
i++;
169
169
}
170
- for(int j = i; j < length; j++) {
171
- if(str[ j] < '0' || str[ j] > '9') {
170
+ for (int j = i; j < length; j++) {
171
+ if (str[ j] < '0' || str[ j] > '9') {
172
172
break;
173
173
}
174
- //res>214748364越界;res=214748364且str[ j] > '7'越界
175
- if(res > bndry || res == bndry && str[ j] > '7'){
174
+ // res>214748364越界;res=214748364且str[ j] > '7'越界
175
+ if (res > bndry || res == bndry && str[ j] > '7') {
176
176
return sign == 1 ? INT_MAX : INT_MIN;
177
177
}
178
- //从左向右遍历数字并更新结果
178
+ // 从左向右遍历数字并更新结果
179
179
res = res * 10 + (str[ j] - '0');
180
180
}
181
181
return sign * res;
You can’t perform that action at this time.
0 commit comments