Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 66e5dc1

Browse files
author
Ram swaroop
committed
done
1 parent 79d27aa commit 66e5dc1

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package me.ramswaroop.arrays;
2+
3+
import me.ramswaroop.arrays.sorting.QuickSort;
4+
5+
/**
6+
* Created by IntelliJ IDEA.
7+
*
8+
* @author: ramswaroop
9+
* @date: 9/4/15
10+
* @time: 11:28 PM
11+
*/
12+
public class SubsetOfArray {
13+
14+
public static boolean isSubsetOfArray(int[] a, int[] b) {
15+
16+
QuickSort.quickSort(a);
17+
QuickSort.quickSort(b);
18+
19+
int i, j;
20+
for (i = 0, j = 0; i < a.length && j < b.length; ) {
21+
if (a[i] > b[j]) {
22+
return false;
23+
} else if (a[i] == b[j]) {
24+
i++;
25+
j++;
26+
} else {
27+
i++;
28+
}
29+
}
30+
31+
if (i < b.length) {
32+
return false;
33+
} else {
34+
return true;
35+
}
36+
}
37+
38+
public static void main(String a[]) {
39+
System.out.println(isSubsetOfArray(new int[]{11, 1, 13, 21, 3, 7}, new int[]{11, 3, 7, 1}));
40+
System.out.println(isSubsetOfArray(new int[]{1, 2, 2, 3, 4, 5, 6}, new int[]{1, 2, 4}));
41+
System.out.println(isSubsetOfArray(new int[]{1, 2, 2, 3, 4, 5, 6}, new int[]{1, 2, 2, 4}));
42+
System.out.println(isSubsetOfArray(new int[]{1, 4, 2}, new int[]{1, 4, 4, 2}));
43+
}
44+
}

0 commit comments

Comments
 (0)