aboutsummaryrefslogtreecommitdiff
path: root/short_encoding_words.cpp
blob: 528191fd5ed4464e8bfc4d5c97f5016ee92ed91d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "leetcode.h"

class Solution {
public:
  int minimumLengthEncoding(vector<string> &words) {
    unordered_set<string> us(words.begin(), words.end());
    for (string w : us)
      for (int i = 1; i < w.size(); ++i)
        us.erase(w.substr(i));
    int ans = 0;
    for (string w : us)
      ans += w.size() + 1;
    return ans;
  }
};

int main() {
  Solution obj;
  vector<string> words = {"time", "me", "bell"};
  cout << obj.minimumLengthEncoding(words);
}