MCPcopy Index your code
hub / github.com/careercup/ctci / checkDuplicates

Method checkDuplicates

java/Chapter 10/Question10_4/Question.java:7–18  ·  view source on GitHub ↗
(int[] array)

Source from the content-addressed store, hash-verified

5public class Question {
6
7 public static void checkDuplicates(int[] array) {
8 BitSet bs = new BitSet(32000);
9 for (int i = 0; i < array.length; i++) {
10 int num = array[i];
11 int num0 = num - 1; // bitset starts at 0, numbers start at 1
12 if (bs.get(num0)) {
13 System.out.println(num);
14 } else {
15 bs.set(num0);
16 }
17 }
18 }
19
20 public static void main(String[] args) {
21 int[] array = AssortedMethods.randomArray(30, 1, 30);

Callers 1

mainMethod · 0.95

Calls 2

getMethod · 0.95
setMethod · 0.95

Tested by

no test coverage detected