Skip to content

Conversation

@skypenguins
Copy link
Owner

929. Unique Email Addresses

次回予告 : 252. Meeting Rooms

@skypenguins skypenguins self-assigned this Sep 22, 2025
for email in emails:
normalized_email = ""
has_plus_sign = False
for i, s in enumerate(email):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文字を表す変数にsを使われたのはなぜでしょうか?
個人的にはsは文字列という印象があるので、c, chあたりにするかなと思いました。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。確かにこれは c のほうが良いですね。

Comment on lines +31 to +32
if s == ".":
continue

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最終的なコードからデバッグ出力は消しておいた方がよいかなと思います

Comment on lines +116 to +117
local_part = local_part.split("+")[0]
local_part = local_part.replace(".", "")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以下のように一行で書くこともできそうです

Suggested change
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以下のようにf-stringで書く方法もあります、個人的には形が分かりやすいのでf-stringの方が好みです

Suggested change
return local_part + "@" + domain_part
return f"{local_part}@{domain_part}"

return len(normalized_emails)
```
- 解答時間: 20:14
- 時間計算量: $O(n^2)$
Copy link

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("@")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local_part domain_partの命名わかりやすいですね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants