diff --git a/2025/01/cracking_code_interview_16_24_pairs_with_sum/src/main/java/pl/polgrabia/demos/crackingcodeinterview/demos/t16x24/Solver.java b/2025/01/cracking_code_interview_16_24_pairs_with_sum/src/main/java/pl/polgrabia/demos/crackingcodeinterview/demos/t16x24/Solver.java index 6365954..814b05c 100644 --- a/2025/01/cracking_code_interview_16_24_pairs_with_sum/src/main/java/pl/polgrabia/demos/crackingcodeinterview/demos/t16x24/Solver.java +++ b/2025/01/cracking_code_interview_16_24_pairs_with_sum/src/main/java/pl/polgrabia/demos/crackingcodeinterview/demos/t16x24/Solver.java @@ -19,14 +19,10 @@ public class Solver { if (nr > el) { continue; } - if (el != nr) { - if (s.getOrDefault(nr, 0) < 1) { - continue; - } - } else { - if (s.getOrDefault(nr, 0) <= 1) { - continue; - } + int existing_count = s.getOrDefault(nr, 0); + int required_count = el == nr ? 2 : 1; + if (required_count > existing_count) { + continue; } solutions.add(new Solution(nr, el)); }