forked from cpsumsu/CodeDaily
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cpsumsu#1 from awepo-pro/main
update leetcode 17 and gitignore file
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,35 @@ | ||
# Prerequisites | ||
*.d | ||
|
||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Fortran module files | ||
*.mod | ||
*.smod | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
|
||
# OS | ||
.DS_Store |
This file contains 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,33 @@ | ||
// https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/ | ||
|
||
class Solution { | ||
public: | ||
// use hash map store as well | ||
const vector<string> pad = { | ||
"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" | ||
}; | ||
|
||
vector<string> letterCombinations(string digits) { | ||
if (digits.empty()) return {}; | ||
|
||
vector<string> result; | ||
// very important to append empty string, otherwise line 19 would not implement for empty vector | ||
result.push_back(""); | ||
|
||
for (auto digit : digits) { | ||
vector<string> tmp; | ||
|
||
for (auto candidate : pad[digit - '2']) { | ||
// for each element in result, append the new character | ||
for (auto s : result) { | ||
// store them into tmp so that tmp currently becomes the answer | ||
tmp.push_back(s + candidate); | ||
} | ||
} | ||
|
||
result.swap(tmp); | ||
} | ||
|
||
return result; | ||
} | ||
}; |