Skip to content

Commit

Permalink
updaintg the difference array
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishektripathi66 committed Sep 16, 2024
1 parent 6e1b729 commit 4f02247
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions Leetcode/DifferenceArray.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import java.util.AbstractList;
import java.util.*;

class DifferenceArray {

public static void main(String[] args) {
DifferenceArray da = new DifferenceArray();
List<List<Integer>> la = da.findDifference(new int[]{1,2,3,3}, new int[]{1,1,2,2});
for(List<Integer> a : la){
System.out.println(a);
}
}

public List<List<Integer>> findDifference(int[] nums1, int[] nums2) {

Expand All @@ -22,16 +31,19 @@ public int size(){
}

private void process(){
first = new ArrayList<>();
second = new ArrayList<>();
byte[] m1 = new byte[2001];
byte[] m2 = new byte[2001];
first = new ArrayList<>(); //initialising the array
second = new ArrayList<>(); //initialising the array
//using size as 2001 coz the values of array range from -1000 to 1000
byte[] m1 = new byte[2001]; //initialising the byte array
byte[] m2 = new byte[2001]; //initialising the byte array
//marking all the numbers of array 2 in the byte
for(int i : nums2){
m1[i+1000]=0b1;
m1[i+1000]=0b1; // adding 1 for present value
}
//check in nums1 array if its present or not
for(int i : nums1){
int x = i+1000;
if(m1[x]!=0b1){
if(m1[x]!=0b1){ // if value not present then add in first
m1[x] = 0b1;
first.add(i);
}
Expand Down

0 comments on commit 4f02247

Please sign in to comment.