diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml
index 8d80528696c0..0a5354382a4f 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 d2b76e8e06b1..520a1681774a 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 @@ public int countGraphs() {
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++;
}