Skip to content

Commit

Permalink
update(cpp-stl): usage of std::equal
Browse files Browse the repository at this point in the history
issue #103
  • Loading branch information
sabertazimi committed Nov 23, 2018
1 parent f218918 commit 837a711
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions language/cpp/cppBasicNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,12 @@ bool is_prefix(const std::string& s, const std::string& of) {
return std::equal(s.begin(), s.end(), of.begin());
}

bool is_suffix(const std::string& s, const std::string& of) {
if (s.size() > of.size()) return false;
auto diff = of.size() - s.size();
return std::equal(s.begin(), s.end(), of.begin() + diff);
}

bool is_palindrome(const std::string& s) {
return std::equal(s.begin(), s.begin() + s.size() / 2, s.rbegin());
}
Expand Down

0 comments on commit 837a711

Please sign in to comment.