Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Tags: Array, Hash Set
package com.leetcode.easy;

import java.util.HashSet;
import java.util.Set;

public class TheTwoSneakyNumbersOfDigitville3289 {
/**
* Finds the two numbers that appear twice in the array.
* <p>
* Time Complexity: O(n) where n is the length of the array.
* We iterate through the array once, and HashSet operations (add, contains) are O(1) on average.
* <p>
* Space Complexity: O(n) for the HashSet to store seen numbers.
* In the worst case, we store almost all numbers before finding the duplicates.
*/
Comment on lines +8 to +16

Copilot AI Jan 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation style is inconsistent with the rest of the codebase. Other solution files in this repository use multi-line block comments with /* / format for complexity analysis, rather than Javadoc-style /* */ comments. Consider changing to the standard block comment format used in files like ContainsDuplicate217.java and TwoSum1.java for consistency.

Copilot uses AI. Check for mistakes.
public int[] getSneakyNumbers(int[] nums) {
int[] res = new int[2];
Set<Integer> seen = new HashSet<>();
int index = 0;
for (int num : nums) {
if (seen.contains(num)) {
res[index] = num;
if (index == 1) {
break;
}
index++;
} else {
seen.add(num);
}
}
return res;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.leetcode.easy;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

public class TheTwoSneakyNumbersOfDigitville3289Test {
private TheTwoSneakyNumbersOfDigitville3289 solution;

@BeforeEach
void setUp() {
solution = new TheTwoSneakyNumbersOfDigitville3289();
}

@Test
void testGetSneakyNumbers_Example1() {
int[] nums = {0, 1, 1, 0};
int[] expected = {0, 1};

int[] result = solution.getSneakyNumbers(nums);
Arrays.sort(result);

assertArrayEquals(expected, result);
}

@Test
void testGetSneakyNumbers_Example2() {
int[] nums = {0, 3, 2, 1, 3, 2};
int[] expected = {2, 3};

int[] result = solution.getSneakyNumbers(nums);
Arrays.sort(result);

assertArrayEquals(expected, result);
}

@Test
void testGetSneakyNumbers_Example3() {
int[] nums = {7, 1, 5, 4, 3, 4, 6, 0, 9, 5, 8, 2};
int[] expected = {4, 5};

int[] result = solution.getSneakyNumbers(nums);
Arrays.sort(result);

assertArrayEquals(expected, result);
}
Comment on lines +18 to +49

Copilot AI Jan 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test coverage could be improved with additional edge cases. Other test files in this repository (e.g., MergeSortedArray88Test.java) include more comprehensive test coverage beyond just the provided examples. Consider adding tests for edge cases such as: a minimal array where n=2 (e.g., [0, 0]), cases where duplicates appear consecutively, or cases where duplicates are at the start or end of the array.

Copilot uses AI. Check for mistakes.
}
Loading