From 31db1af345b0635633d962a944210edaff3d5251 Mon Sep 17 00:00:00 2001 From: Piotr Idzik <65706193+vil02@users.noreply.github.com> Date: Thu, 13 Jun 2024 19:27:49 +0200 Subject: [PATCH] style: include `SUI_CONTAINS_BEFORE_ADD` (#5216) --- spotbugs-exclude.xml | 3 --- .../datastructures/graphs/ConnectedComponent.java | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml index 8d8052869..0a5354382 100644 --- a/spotbugs-exclude.xml +++ b/spotbugs-exclude.xml @@ -222,9 +222,6 @@ - - - diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/ConnectedComponent.java b/src/main/java/com/thealgorithms/datastructures/graphs/ConnectedComponent.java index d2b76e8e0..520a16817 100644 --- a/src/main/java/com/thealgorithms/datastructures/graphs/ConnectedComponent.java +++ b/src/main/java/com/thealgorithms/datastructures/graphs/ConnectedComponent.java @@ -81,8 +81,7 @@ class Graph> { Set markedNodes = new HashSet(); for (Node n : nodeList) { - if (!markedNodes.contains(n)) { - markedNodes.add(n); + if (markedNodes.add(n)) { markedNodes.addAll(depthFirstSearch(n, new ArrayList())); count++; }