Commit 3835c48
Refactor: simplify validation and improve backtracking cleanup (#7258)
### Summary
This PR makes small readability and maintainability improvements to the algorithm implementation.
### Changes
- Removed a redundant `n < 0` validation check since the method contract already ensures valid `n`
- Replaced `current.remove(current.size() - 1)` with `current.removeLast()` to better express backtracking intent
### Rationale
- Simplifies input validation without changing behavior
- Uses the `Deque` API to make the backtracking step clearer and less error-prone
### Impact
- No change in algorithm logic or time/space complexity
- Output remains identical
Co-authored-by: Swati Vusurumarthi <swativs869@gmail.com>1 parent 249b88f commit 3835c48
File tree
1 file changed
+3
-3
lines changed- src/main/java/com/thealgorithms/backtracking
1 file changed
+3
-3
lines changedLines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
| 23 | + | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
0 commit comments