My LeetCode member has expired again. Just leave the code here and I will check it out later.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
string (string s, int i){ string abbre = s.substr(0, i); abbre += to_string(s.length()-1-i); abbre += s.back(); return abbre; }
vector<string> wordsAbbreviation(vector<string>& dict) { int size = dict.size(); vector<int> prefix(size, 1); vector<string> abbre(size, ""); for(int i = 0; i < size; i++){ abbre[i] = getAbbre(dict[i], 1); } for(int i = 0; i < size; i++){ while(true){ set<int> dupli; for(int j = i+1; j < size; j++){ if(abbre[j] == abbre[i]) dupli.insert(j); } if(dupli.empty()) break; dupli.insert(i); for(auto it = dupli.begin(); it != dupli.end(); it++){ abbre[*it] = getAbbre(dict[*it], ++prefix[*it]); } } } return abbre; }
|
近期评论