From ff4c4d563abf10295f627dea879cbcdf6e3095e4 Mon Sep 17 00:00:00 2001 From: sakshivij Date: Fri, 11 Oct 2019 16:37:52 +0530 Subject: [PATCH] Remove Duplicates from array --- #442/Solution.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 #442/Solution.java diff --git a/#442/Solution.java b/#442/Solution.java new file mode 100644 index 0000000..ffc77a2 --- /dev/null +++ b/#442/Solution.java @@ -0,0 +1,24 @@ +import java.util.*; + +class Solution { + public List findDuplicates(int[] nums) { + int n = nums.length; + int x = -1; + ArrayList list = new ArrayList<>(); + for(int i=0; i=0 ) + x = nums[i]; + else + x = nums[i] + n +1 ; + + if(nums[x - 1] >= 0 ) + nums[x - 1] = nums[x - 1] - (n +1); + else + list.add(x); + + } + + return list; + } +} \ No newline at end of file