From 16af63e22ad0d3522c19ccf5eb3dd4a0b4294a9e Mon Sep 17 00:00:00 2001 From: Shuo Zhang Date: Mon, 27 Jun 2022 22:54:52 -0400 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B90349=20-=20=E7=94=A8=20Java?= =?UTF-8?q?=20stream=20=E4=BB=A3=E6=9B=BF=20for=20loop=20(=E8=BF=99?= =?UTF-8?q?=E6=A0=B7=E4=B8=BB=E9=A2=98=E6=9B=B4=E6=98=8E=E6=98=BE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0349.两个数组的交集.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/problems/0349.两个数组的交集.md b/problems/0349.两个数组的交集.md index 98518647..2a8b2dae 100644 --- a/problems/0349.两个数组的交集.md +++ b/problems/0349.两个数组的交集.md @@ -104,13 +104,8 @@ class Solution { resSet.add(i); } } - int[] resArr = new int[resSet.size()]; - int index = 0; //将结果几何转为数组 - for (int i : resSet) { - resArr[index++] = i; - } - return resArr; + return resSet.stream().mapToInt(x -> x).toArray(); } } ```