349.最后返回数组添加另一种写法,更多人容易理解看懂

This commit is contained in:
hbingzhi
2023-01-08 12:58:54 +08:00
parent fe0d0f8c5b
commit 2d2babdaf0

View File

@ -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#:
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>