File tree 5 files changed +51
-18
lines changed
main/java/io/github/spannm/leetcode
test/java/io/github/spannm/leetcode
5 files changed +51
-18
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import io .github .spannm .leetcode .LeetcodeProblem ;
4
4
5
- import java .util .* ;
5
+ import java .util .Arrays ;
6
6
7
+ /**
8
+ * 350. Intersection of Two Arrays II.
9
+ */
7
10
class Problem0350 extends LeetcodeProblem {
8
11
9
12
int [] intersect (int [] _nums1 , int [] _nums2 ) {
10
- Map <Integer , Integer > map = new HashMap <>();
11
- for (int i : _nums1 ) {
12
- map .compute (i , (k , v ) -> v == null ? 1 : v + 1 );
13
- }
14
-
15
- List <Integer > list = new ArrayList <>();
16
- for (int i : _nums2 ) {
17
- int val = Objects .requireNonNullElse (map .get (i ), 0 );
18
- if (val > 0 ) {
19
- list .add (i );
20
- map .put (i , val - 1 );
21
- }
22
- }
23
- return list .stream ().mapToInt (i -> i ).toArray ();
13
+ int [] counts = new int [1001 ];
14
+ Arrays .stream (_nums1 ).forEach (n -> counts [n ]++);
15
+ return Arrays .stream (_nums2 ).filter (n -> counts [n ]-- > 0 ).toArray ();
24
16
}
25
17
26
18
}
Original file line number Diff line number Diff line change
1
+ package io .github .spannm .leetcode .lc1 .lc1300 ;
2
+
3
+ import io .github .spannm .leetcode .LeetcodeSqlProblem ;
4
+
5
+ /**
6
+ * 1350. Students With Invalid Departments.
7
+ */
8
+ public class Problem1350 extends LeetcodeSqlProblem {
9
+
10
+ Problem1350 () {
11
+ super ("""
12
+ SELECT id, name
13
+ FROM Students
14
+ WHERE department_id NOT IN (SELECT id FROM Departments)""" );
15
+ }
16
+
17
+ }
Original file line number Diff line number Diff line change
1
+ package io .github .spannm .leetcode .lc0 .lc0300 ;
2
+
3
+ import static org .assertj .core .api .Assertions .assertThat ;
4
+
5
+ import io .github .spannm .leetcode .LeetcodeBaseTest ;
6
+ import org .junit .jupiter .params .ParameterizedTest ;
7
+ import org .junit .jupiter .params .converter .ConvertWith ;
8
+ import org .junit .jupiter .params .provider .CsvSource ;
9
+
10
+ class Problem0350Test extends LeetcodeBaseTest {
11
+ @ ParameterizedTest (name = "[{index}] {0}; {1} --> {2}" )
12
+ @ CsvSource (delimiter = ';' , value = {
13
+ "1,2,2,1; 2,2; 2,2" ,
14
+ "4,9,5; 9,4,9,8,4; 4,9"
15
+ })
16
+ void test (
17
+ @ ConvertWith (CsvToIntArray .class ) int [] _nums1 ,
18
+ @ ConvertWith (CsvToIntArray .class ) int [] _nums2 ,
19
+ @ ConvertWith (CsvToIntArray .class ) int [] _expectedResult ) {
20
+ int [] actual = new Problem0350 ().intersect (_nums1 , _nums2 );
21
+ assertThat (actual ).containsExactlyInAnyOrder (_expectedResult );
22
+ }
23
+ }
Original file line number Diff line number Diff line change 1
1
package io .github .spannm .leetcode .lc2 .lc2100 ;
2
2
3
3
import io .github .spannm .leetcode .LeetcodeBaseTest ;
4
- import java .util .List ;
5
4
import org .junit .jupiter .params .ParameterizedTest ;
6
5
import org .junit .jupiter .params .converter .ConvertWith ;
7
6
import org .junit .jupiter .params .provider .CsvSource ;
8
7
8
+ import java .util .List ;
9
+
9
10
class Problem2192Test extends LeetcodeBaseTest {
10
11
@ ParameterizedTest (name = "[{index}] {0}; {1} --> {2}" )
11
12
@ CsvSource (delimiter = ';' , value = {
Original file line number Diff line number Diff line change @@ -182,8 +182,8 @@ boolean createUnitTest(Class<?> _clazz) throws IOException {
182
182
}
183
183
184
184
Method findTestMethod (Class <?> _clazz ) {
185
- List <Method > list = Arrays .stream (_clazz .getDeclaredMethods ().length > 0 ? _clazz .getDeclaredMethods () :
186
- Arrays .stream (_clazz .getDeclaredClasses ())
185
+ List <Method > list = Arrays .stream (_clazz .getDeclaredMethods ().length > 0 ? _clazz .getDeclaredMethods ()
186
+ : Arrays .stream (_clazz .getDeclaredClasses ())
187
187
.filter (c -> Modifier .isStatic (c .getModifiers ()))
188
188
.map (Class ::getDeclaredMethods )
189
189
.filter (arr -> arr .length > 0 )
You can’t perform that action at this time.
0 commit comments