Skip to content

Commit

Permalink
add 929
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed Oct 29, 2018
1 parent 8448a02 commit ec3a0eb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ LeetCode
|0120|[Triangle](https://leetcode.com/problems/triangle/) | c | [c++](./src/0120-Triangle/0120.cpp) |[python](./src/0120-Triangle/0120.py)|||Medium|
|0121|[Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) | c | [c++](./src/0121-Best-Time-to-Buy-and-Sell-Stock/0121.cpp) |[python](./src/0121-Best-Time-to-Buy-and-Sell-Stock/0121.py)|||Easy|
|0122|[Best Time to Buy and Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/) | c | [c++](./src/0122-Best-Time-to-Buy-and-Sell-Stock-II/0122.cpp) |[python](./src/0122-Best-Time-to-Buy-and-Sell-Stock-II/0122.py)|||Easy|
|0123|[Best Time to Buy and Sell Stock III](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/) | c | [c++](./src/0123-Best-Time-to-Buy-and-Sell-Stock-III/0123.cpp) |[python](./src/0123-Best-Time-to-Buy-and-Sell-Stock-III/0123.py)|||Hard|
|0125|[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) | c | [c++](./src/0125-Valid-Palindrome/0125.cpp) |[python](./src/0125-Valid-Palindrome/0125.py)|||Easy|
|0126|[Word Ladder II](https://leetcode.com/problems/word-ladder-ii/) | c | [c++](./src/0126-Word-Ladder-II/0126.cpp) |[python](./src/0126-Word-Ladder-II/0126.py)|||Hard|
|0127|[Word Ladder](https://leetcode.com/problems/word-ladder/) | c | [c++](./src/0127-Word-Ladder/0127.cpp) |[python](./src/0127-Word-Ladder/0127.py)|||Medium|
Expand Down Expand Up @@ -166,4 +167,5 @@ LeetCode
|0923|[3Sum With Multiplicity](https://leetcode.com/problems/3sum-with-multiplicity/) | c | [c++](./src/0923-3Sum-With-Multiplicity/0923.cpp) |[python](./src/0923-3Sum-With-Multiplicity/0923.py)|||Medium|
|0925|[Long Pressed Name](https://leetcode.com/problems/long-pressed-name/) | c | [c++](./src/0925-Long-Pressed-Name/0925.cpp) |[python](./src/0925-Long-Pressed-Name/0925.py)|||Easy|
|0926|[Flip String to Monotone Increasing](https://leetcode.com/problems/flip-string-to-monotone-increasing/) | c | [c++](./src/0926-Flip-String-to-Monotone-Increasing/0926.cpp) |[python](./src/0926-Flip-String-to-Monotone-Increasing/0926.py)|||Medium|
|0927|[Three Equal Parts](https://leetcode.com/problems/three-equal-parts/) | c | [c++](./src/0927-Three-Equal-Parts/0927.cpp) |[python](./src/0927-Three-Equal-Parts/0927.py)|||Medium|
|0927|[Three Equal Parts](https://leetcode.com/problems/three-equal-parts/) | c | [c++](./src/0927-Three-Equal-Parts/0927.cpp) |[python](./src/0927-Three-Equal-Parts/0927.py)|||Medium|
|0929|[Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses/) | c | [c++](./src/0925-Long-Pressed-Name/0925.cpp) |[python](./src/0925-Long-Pressed-Name/0925.py)|||Easy|
41 changes: 41 additions & 0 deletions src/0929-Unique-Email-Addresses/0929.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
using namespace std;

static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
int numUniqueEmails(vector<string>& emails)
{
unordered_set<string> result;
for (auto& email : emails)
{
auto at_pos = email.find('@');
auto plus_pos = email.find('+');
if (plus_pos < at_pos)
{
auto len = at_pos - plus_pos;
email.erase(plus_pos, len);
at_pos -= len;
}
auto dot_pos = email.find('.');
while (dot_pos < at_pos)
{
email.erase(dot_pos, 1);
at_pos--;
dot_pos = email.find('.');
}
result.insert(email);
}
return result.size();
}
};
int main()
{
vector<string> emails = {"[email protected]","[email protected]","[email protected]"};
cout << Solution().numUniqueEmails(emails);
return 0;
}
18 changes: 18 additions & 0 deletions src/0929-Unique-Email-Addresses/0929.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
def numUniqueEmails(self, emails):
"""
:type emails: List[str]
:rtype: int
"""
raw_emails = set()
for email in emails:
sp_at = email.split('@')
pre = sp_at[0].split('+')
raw_emails.add(pre[0].replace('.', '') + sp_at[1])

return len(raw_emails)


if __name__ == "__main__":
emails = ["[email protected]","[email protected]","[email protected]"]
print(Solution().numUniqueEmails(emails))

0 comments on commit ec3a0eb

Please sign in to comment.