-
Notifications
You must be signed in to change notification settings - Fork 0
929. Unique Email Addresses #24
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
base: main
Are you sure you want to change the base?
Conversation
| for email in emails: | ||
| normalized_email = "" | ||
| has_plus_sign = False | ||
| for i, s in enumerate(email): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文字を表す変数にsを使われたのはなぜでしょうか?
個人的にはsは文字列という印象があるので、c, chあたりにするかなと思いました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとうございます。確かにこれは c のほうが良いですね。
| if s == ".": | ||
| continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こちらの条件は無くてもよいかなと思いました
|
|
||
| normalized_emails.add(normalized_email) | ||
|
|
||
| print(normalized_emails) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最終的なコードからデバッグ出力は消しておいた方がよいかなと思います
| local_part = local_part.split("+")[0] | ||
| local_part = local_part.replace(".", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以下のように一行で書くこともできそうです
| local_part = local_part.split("+")[0] | |
| local_part = local_part.replace(".", "") | |
| local_part = local_part.split("+")[0].replace(".", "") |
| local_part, domain_part = email.split("@") | ||
| local_part = local_part.split("+")[0] | ||
| local_part = local_part.replace(".", "") | ||
| return local_part + "@" + domain_part |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以下のようにf-stringで書く方法もあります、個人的には形が分かりやすいのでf-stringの方が好みです
| return local_part + "@" + domain_part | |
| return f"{local_part}@{domain_part}" |
| return len(normalized_emails) | ||
| ``` | ||
| - 解答時間: 20:14 | ||
| - 時間計算量: $O(n^2)$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文字列の個数と文字の長さは分けた方が良いのでO(M * N)などの記載が良いと思います
| class Solution: | ||
| def numUniqueEmails(self, emails: List[str]) -> int: | ||
| def canonicalize(email: str) -> str: | ||
| local_part, domain_part = email.split("@") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local_part domain_partの命名わかりやすいですね。
929. Unique Email Addresses
次回予告 : 252. Meeting Rooms