Commit e984169
authored
Here’s an optimized version of your program. The current code repeatedly computes `int(0.75 * len(s))` and slices the string, which is already fast, but can be micro-optimized.
- Avoid the float multiplication and casting by directly calculating `(len(s) * 3) // 4`, which is faster and avoids possible floating-point artifacts.
Rewritten code.
This version removes the float operation and is slightly faster, especially for large strings. The return value is exactly the same as before.
1 parent f5bfcd9 commit e984169
1 file changed
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| |||
0 commit comments