forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 1
[pull] master from wisdompeak:master #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
371c2d7
Update 1467.Probability-of-a-Two-Boxes-Having-The-Same-Number-of-Dist...
wisdompeak 73253bc
Update Readme.md
wisdompeak ab3d422
Update and rename 527.Word Abbreviation.cpp to 527.Word-Abbreviation.cpp
wisdompeak 94f9a00
Update 527.Word-Abbreviation.cpp
wisdompeak ad229fb
Update Readme.md
wisdompeak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,5 @@ C(i,j) = C(i-1, j-1) + C(i-1, j) | |
} | ||
} | ||
``` | ||
|
||
本题的时间DFS的复杂度是`6^8 = 1679616`,可以接受, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
String/527.Word-Abbreviation/527.Word Abbreviation.cpp
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
String/527.Word-Abbreviation/527.Word-Abbreviation.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
class Solution { | ||
public: | ||
vector<string> wordsAbbreviation(vector<string>& words) | ||
{ | ||
int n = words.size(); | ||
vector<string>rets(n); | ||
|
||
vector<int>Set; | ||
for (int i=0; i<n; i++) | ||
Set.push_back(i); | ||
|
||
int abbrNum = 1; | ||
while (1) | ||
{ | ||
unordered_map<string, vector<int>> Map; | ||
|
||
for (int idx: Set) | ||
{ | ||
string abbr = getAbbr(words[idx], abbrNum); | ||
Map[abbr].push_back(idx); | ||
} | ||
Set.clear(); | ||
|
||
for (auto& [abbr, indices]: Map) | ||
{ | ||
if (indices.size() > 1) | ||
{ | ||
for (int idx: indices) | ||
Set.push_back(idx); | ||
} | ||
else | ||
rets[indices[0]] = abbr; | ||
} | ||
|
||
abbrNum += 1; | ||
if (Set.size() == 0) | ||
break; | ||
} | ||
|
||
return rets; | ||
} | ||
|
||
string getAbbr(string s, int abbrNum) | ||
{ | ||
if (s.size() < 3) return s; | ||
|
||
string t; | ||
t = s.substr(0, abbrNum); | ||
t += to_string(s.size() - abbrNum - 1); | ||
t += s.back(); | ||
|
||
if (t.size() == s.size()) return s; | ||
|
||
return t; | ||
} | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.