From 40620aea1b728c9a8fd1f931ec503660dd06e8c9 Mon Sep 17 00:00:00 2001 From: joshiujjawal22 Date: Mon, 18 May 2020 23:24:57 +0530 Subject: [PATCH] To find sum of triplets according to given value --- Others/3 sum.java | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Others/3 sum.java diff --git a/Others/3 sum.java b/Others/3 sum.java new file mode 100644 index 000000000..3c008ff78 --- /dev/null +++ b/Others/3 sum.java @@ -0,0 +1,48 @@ +package Others; + +import java.util.Scanner; +import java.util.Arrays; + +/** + * To find triplet equals to given sum in complexity O(n*log(n)) + * + * + * Array must be sorted + * + * @author Ujjawal Joshi + * @date 2020.05.18 + */ + + +class threesum{ + public static void main(String args[]) + { + Scanner sc =new Scanner(System.in); + int n=sc.nextInt(); //Length of an array + + int a[]=new int[n]; + + for(int i=0;i