Skip to content

Commit cc3e293

Browse files
authored
feat: add solution(s) to lc problem(s): No.67
1 parent 9512ed6 commit cc3e293

File tree

1 file changed

+11
-11
lines changed
  • lcof/面试题67. 把字符串转换成整数

1 file changed

+11
-11
lines changed

lcof/面试题67. 把字符串转换成整数/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,31 +151,31 @@ public:
151151
int StrToInt(string str) {
152152
int res = 0, bndry = INT_MAX / 10;
153153
int i = 0, sign = 1, length = str.size();
154-
if(length == 0) {
154+
if (length == 0) {
155155
return 0;
156156
}
157157
// 删除首部空格
158-
while(str[i] == ' '){
159-
if(++i == length) {
158+
while (str[i] == ' ') {
159+
if (++i == length) {
160160
return 0;
161161
}
162162
}
163-
//若有负号则标识符号位
164-
if(str[i] == '-') {
163+
// 若有负号则标识符号位
164+
if (str[i] == '-') {
165165
sign = -1;
166166
}
167-
if(str[i] == '-' || str[i] == '+') {
167+
if (str[i] == '-' || str[i] == '+') {
168168
i++;
169169
}
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') {
172172
break;
173173
}
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') {
176176
return sign == 1 ? INT_MAX : INT_MIN;
177177
}
178-
//从左向右遍历数字并更新结果
178+
// 从左向右遍历数字并更新结果
179179
res = res * 10 + (str[j] - '0');
180180
}
181181
return sign * res;

0 commit comments

Comments
 (0)