Skip to content

Commit fd64978

Browse files
committed
do not use division
1 parent 2366d13 commit fd64978

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

analysis/add-two-numbers.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515

1616
##注意:
17-
99+99这样的情况会产生更高位
17+
1. 99+99这样的情况会产生更高位
18+
2. 别用除法,获得进位时用了除法多用3倍时间
1819

1920

2021

src/AddTwoNumbers.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ class Solution {
2121

2222
if (num >= 10){
2323
p->val = num % 10;
24-
num = num/10;
24+
## num=num/10运行时间220ms
25+
// num = num/10;
26+
## num=1运行时间50ms,除法消耗的时间不容小觑
27+
num = 1;
2528
} else {
2629
p->val = num;
2730
num = 0;

0 commit comments

Comments
 (0)