diff --git a/Algorithms/Implementation/Beautiful Triplets/Solution.java b/Algorithms/Implementation/Beautiful Triplets/Solution.java index c2f6e88..de943c5 100644 --- a/Algorithms/Implementation/Beautiful Triplets/Solution.java +++ b/Algorithms/Implementation/Beautiful Triplets/Solution.java @@ -10,7 +10,7 @@ public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int d = input.nextInt(); - + List arr = new ArrayList<>(); // to add all Array Elements as It will be used Later Set values = new HashSet<>(); int beautifulTriplets = 0; @@ -20,7 +20,7 @@ public static void main(String[] args) { for(int i = 0; i < n; i++) { int x = input.nextInt(); - + arr.add(x); if(!values.contains(x)) { values.add(x); @@ -29,7 +29,7 @@ public static void main(String[] args) { //Check if set has a value, value+d, and value + 2d - for(Integer digit : values) + for(Integer digit : arr) // use " arr " in place of " values " as if the input Value have any Repetition it need to be Counted. { if(values.contains(digit+d) && values.contains(digit+(2*d))) { @@ -39,4 +39,4 @@ public static void main(String[] args) { System.out.println(beautifulTriplets); } -} \ No newline at end of file +}