#16. Intersection of Two Arrays II | (LeetCode #350) | Data Structure And Algorithm

preview_player
Показать описание
#16. Intersection of Two Arrays II | (LeetCode #350) | Data Structure And Algorithm

code :- First comment

If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful
Рекомендации по теме
Комментарии
Автор

class Solution {
public int[] intersect(int[] nums1, int[] nums2) {
List<Integer> al =new ArrayList<Integer>();
for(int num:nums1){
al.add(num);
}
List<Integer> al1 =new ArrayList<Integer>();
for(int num:nums2){
if(al.contains(num)){
al.remove(al.indexOf(num));
al1.add(num);
}
}
int i=0;
int ans[] = new int[al1.size()];
for(Integer num:al1){
ans[i++] = num;
}
return ans;
}
}

thecodebrothers
join shbcf.ru