回答編集履歴

1

コメントの指摘修正

2018/06/27 08:00

投稿

takezoux2
takezoux2

スコア3

test CHANGED
@@ -22,7 +22,23 @@
22
22
 
23
23
 
24
24
 
25
+ // 要素が増えてくるとHashSetに一旦入れたほうが処理が早くなります
26
+
27
+ var allItemSet = new HashSet<string>(item1);
28
+
29
+ foreach(var item in item2) {
30
+
31
+ allItemSet.Add(item);
32
+
33
+ }
34
+
35
+
36
+
25
37
  foreach( var s in searchlist) {
38
+
39
+ if(!allItemSet.Contains(s)) continue;
40
+
41
+
26
42
 
27
43
  item1Set.Add(s); // 重複要素は追加されないので、なにもチェックする必要なし
28
44
 
@@ -42,9 +58,21 @@
42
58
 
43
59
  // itemXが複数バージョン
44
60
 
45
- var itemLists = new List<string[]>(){item1, item2, ...}.Select(items => new HashSet<string>(items)).ToList();
61
+ var itemLists = new List<string[]>(){item1, item2, ...}
62
+
63
+ .Select(items => new HashSet<string>(items))
64
+
65
+ .ToList();
66
+
67
+ var allItemSet = new HashSet<string>(itemLists.SelectMany(_ => _));
68
+
69
+
46
70
 
47
71
  foreach(var s in serachlist) {
72
+
73
+ if(!allItemSet.Contains(s)) continue;
74
+
75
+
48
76
 
49
77
  foreach(var itemSet in itemLists) {
50
78