回答編集履歴
1
finalの付け忘れ
answer
CHANGED
|
@@ -44,38 +44,41 @@
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
public static Long checkAndDelSeparate(List<String> list) {
|
|
47
|
+
final long count =
|
|
47
|
-
|
|
48
|
+
list.stream().filter((str) -> str.startsWith("h")).count();
|
|
48
49
|
list.replaceAll((str) -> str.startsWith("h") ? str.substring(1) : str);
|
|
49
50
|
|
|
50
51
|
return count;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
public static Long checkAndDelOnce(List<String> list) {
|
|
54
|
-
SimpleImmutableEntry<Long, List<String>> result =
|
|
55
|
+
final SimpleImmutableEntry<Long, List<String>> result =
|
|
56
|
+
list.stream().reduce(
|
|
55
|
-
|
|
57
|
+
new SimpleImmutableEntry<Long, List<String>>(
|
|
56
|
-
|
|
58
|
+
new Long(0), Collections.emptyList()),
|
|
57
|
-
|
|
59
|
+
(acc, str)
|
|
58
|
-
|
|
60
|
+
-> {
|
|
59
|
-
|
|
61
|
+
final Long accCount = acc.getKey();
|
|
60
|
-
|
|
62
|
+
final Stream<String> accStream = acc.getValue().stream();
|
|
61
|
-
|
|
63
|
+
final BiFunction<Boolean, String,
|
|
62
|
-
|
|
64
|
+
SimpleImmutableEntry<Long, List<String>>>
|
|
63
|
-
|
|
65
|
+
createPair = (incr, s)
|
|
64
|
-
|
|
66
|
+
-> new SimpleImmutableEntry<Long, List<String>>(
|
|
65
|
-
|
|
67
|
+
incr ? accCount : accCount + 1,
|
|
66
|
-
|
|
68
|
+
Stream.concat(accStream, Stream.of(s))
|
|
67
|
-
|
|
69
|
+
.collect(Collectors.toList()));
|
|
68
70
|
|
|
71
|
+
return str.startsWith("h")
|
|
69
|
-
|
|
72
|
+
? createPair.apply(true, str.substring(1))
|
|
70
|
-
|
|
73
|
+
: createPair.apply(false, str);
|
|
71
|
-
|
|
74
|
+
},
|
|
72
|
-
|
|
75
|
+
(a, b)
|
|
73
|
-
|
|
76
|
+
-> new SimpleImmutableEntry<Long, List<String>>(
|
|
74
|
-
|
|
77
|
+
a.getKey() + b.getKey(),
|
|
75
|
-
|
|
78
|
+
Stream.concat(a.getValue().stream(), b.getValue().stream())
|
|
76
|
-
|
|
79
|
+
.collect(Collectors.toList()))
|
|
77
80
|
|
|
78
|
-
|
|
81
|
+
);
|
|
79
82
|
final Iterator<String> itr = result.getValue().iterator();
|
|
80
83
|
list.replaceAll((_s) -> itr.next());
|
|
81
84
|
|