diff --git a/problems/0349.两个数组的交集.md b/problems/0349.两个数组的交集.md index 2e98ef6f..6f5a34e7 100644 --- a/problems/0349.两个数组的交集.md +++ b/problems/0349.两个数组的交集.md @@ -137,8 +137,18 @@ class Solution { resSet.add(i); } } - //将结果几何转为数组 + + //方法1:直接将结果几何转为数组 return resSet.stream().mapToInt(x -> x).toArray(); + + //方法2:另外申请一个数组存放setRes中的元素,最后返回数组 + int[] arr = new int[setRes.size()]; + int j = 0; + for(int i : setRes){ + arr[j++] = i; + } + + return arr; } } ``` @@ -423,3 +433,4 @@ C#: +