leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2645.cpp (361B)


0 class Solution { 1 public: 2 int addMinimum(const string &word) const { 3 static const int add[3][3] = {{2, 1, 0}, {0, 2, 1}, {1, 0, 2}}; 4 int res = 0, prev = 2; 5 6 for (const char c : word) { 7 const int idx = c - 'a'; 8 res += add[idx][prev]; 9 prev = idx; 10 } 11 12 return res + 2 - prev; 13 } 14 };