Advertisement
Hiteshw11

Common Elements In Three Lists

Nov 24th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.46 KB | Source Code | 0 0
  1. /* Common Elements in Three Lists */
  2.  
  3. void main()
  4. {
  5.   List<int> list1=[1,2,3];
  6.   List<int> list2=[2,3,4];
  7.   List<int> list3=[3,4,5];
  8.   print(commonElements(list1,list2,list3));
  9. }
  10.  
  11. List<int> commonElements(List<int> list1,List<int> list2, List<int> list3)
  12. {
  13.   Set <int> s1=list1.toSet();
  14.   Set <int> s2=list2.toSet();
  15.   Set <int> s3=list3.toSet();
  16.  
  17.   Set <int> s4=s1.intersection(s2).intersection(s3);
  18.   List <int> list4=s4.toList();
  19.   return list4;
  20. }
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement