Skip to content

Commit

Permalink
Add leetcode problem of the day #ct
Browse files Browse the repository at this point in the history
  • Loading branch information
iglesias authored Jun 1, 2024
1 parent fb9bfeb commit d867393
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions leetcode/3110.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <algorithm>
#include <array>
#include <cmath>
#include <numeric>
#include <string_view>

constexpr int score(std::string_view s)
{
std::array<int, 1024> 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(){}

0 comments on commit d867393

Please sign in to comment.