From 4c75481155eaeeee8f8e2ed9ec58003cfbdf1721 Mon Sep 17 00:00:00 2001 From: God-OfTruth <62745804+God-OfTruth@users.noreply.github.com> Date: Fri, 28 Jan 2022 16:29:35 +0530 Subject: [PATCH] Update Solution.java Add all input Array in ArrayList or normal Array at time of Checking for value + d and value+2d use above array as it input has duplicate elements. --- .../Implementation/Beautiful Triplets/Solution.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 +}