Skip to content

Commit 1ef6af0

Browse files
committed
remove_if を自前実装した
1 parent 3ac0bac commit 1ef6af0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

125/1.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
// 第1段階のコード
22
class Solution {
33
public:
4+
5+
template<class ForwardIt, class UnaryPredicate>
6+
ForwardIt remove_if(ForwardIt first, ForwardIt last, UnaryPredicate p) {
7+
ForwardIt filteredLast = first;
8+
while (first != last) {
9+
if (!p(*first)) {
10+
*filteredLast = *first;
11+
filteredLast++;
12+
}
13+
first++;
14+
}
15+
16+
return filteredLast;
17+
}
18+
419
bool isPalindrome(string s) {
520
string checker = s;
621
checker.erase(
@@ -16,6 +31,8 @@ class Solution {
1631

1732
reverse(checkerReverse.begin(), checkerReverse.end());
1833

34+
cout << checker << endl << checkerReverse << endl;
35+
1936
return (checker == checkerReverse);
2037
}
2138
};

0 commit comments

Comments
 (0)