diff --git a/leetcode/3110.cpp b/leetcode/3110.cpp new file mode 100644 index 0000000..118c339 --- /dev/null +++ b/leetcode/3110.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include + +constexpr int score(std::string_view s) +{ + std::array v; + std::adjacent_difference(s.cbegin(), s.cend(), v.begin()); + return std::accumulate(std::next(v.cbegin()), + v.cbegin() + s.length(), + 0, + [](int acc, const int val) { + return acc += std::abs(val); + }); +} + +static_assert(score("hello") == 13); +static_assert(score("platypus") == 55); +static_assert(score("honorificabilitudinitatibus") == 181); + +int main(){}