Commit 1310573
authored
⚡️ Speed up function
Here is an optimized version of your program.
Key improvements.
- The `for` loop for `k` is replaced with a formula for arithmetic series sum, eliminating iteration.
- The sum for `j` is done via the same formula (since sum(range(number)) is (number-1)*number//2).
- Used a list comprehension for `str(i)` and `join`, which is slightly faster than the generator form in this context.
This version will run much faster, especially for large `number` values. All logic and return values are preserved.funcA by 5,026%1 parent 03116d2 commit 1310573
1 file changed
Lines changed: 7 additions & 8 deletions
Lines changed: 7 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
0 commit comments