Skip to content

929. Unique Email Addresses#14

Open
miyataka wants to merge 1 commit into
mainfrom
929_UniqueEmailAddresses
Open

929. Unique Email Addresses#14
miyataka wants to merge 1 commit into
mainfrom
929_UniqueEmailAddresses

Conversation

@miyataka

Copy link
Copy Markdown
Owner

- uniqueEmails は O(N)のサイズがあればよい
- ひとつひとつのエントリはO(M)
- よって全体としてはO(NM)
- 1文字は1byteとする. emails.length <= 100, emails[i].length <= 100となっているので,

@h-masder h-masder Jun 14, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

もう少し丁寧に書いてもいいかなと思いました。
例えば「UTF-8でエンコードすると仮定すると、 小文字の英語, '+', '.', '@' は1byteである」などです。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

これはその通りですね
ありがとうございます

- LLMより,`strings.Cut`
という関数を教えてもらったのでこれのバージョンを書いてみたが,別にわかりやすくもないような...
- https://pkg.go.dev/strings#Cut
- もっと実務的なvalidationが必要になる場合には `net/mail.ParseAddress` を利用するのがよさそう

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

言及されているように、今の制約ならどうか、その制約が変わったらどうかを考えるのは大事だと思います。

実務的なvalidationが必要になる場合

これでいうと、以下のようなものが背景知識になるかと思います。
・現実のメールを構成する文字の種類はもっと多い。(RFC5321など)
・ただし、RFCに忠実に従おうとすると、メールアドレスのバリデーションは複雑になる(https://www.regular-expressions.info/email.html)
・(場合によっては、バリデーションはステートマシンで書いたほうがシンプルにわかりやすくなるなるかもしれません。)

ご覧になっていなければ、コメント集を見るのもよいと思います。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

コメント集を確認できてなかったので確認します

ありがとうございます!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

みました.

ステートマシン
エラー処理をどうするかについてのやりとり(どんなユースケースを想定しているか)
コピーをするかどうかの選択

https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.h73uwlfq793n

言及されているあたりを思い浮かべながら,それを伝える訓練としてPRを作れるとよさそうですね

(返信不要です)

uniqueEmails := map[string]bool{}
for _, email := range emails {
splited := strings.Split(email, "@")
localname, domain := splited[0], splited[1]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

問題文中で local name と domain name となっているにもかかわらず、 localname と domain と name が付いているのといないのとで統一されていない点に違和感を感じました。どちらかに統一するとよいと思います。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

たしかに,統一感のない命名でした.ご指摘ありがとうございます

uniqueEmails := map[string]bool{}
for _, email := range emails {
splited := strings.Split(email, "@")
localname, domain := splited[0], splited[1]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

自分なら localName とすると思います。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

こちらもGoの慣習から外れた命名でした.ご指摘ありがとうございます

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants