Conversation
oda
reviewed
Jun 15, 2024
| public: | ||
| int numUniqueEmails(vector<string>& emails) { | ||
| set<string> unique_emails; | ||
| for (auto email : emails) { |
oda
reviewed
Jun 15, 2024
| @@ -0,0 +1,27 @@ | |||
| class Solution { | |||
| private: | |||
| string canonicalize(string email) { | |||
Owner
Author
| break; | ||
| } | ||
| if (email[i] != '.') { | ||
| canonicalized_email += email[i]; |
There was a problem hiding this comment.
C++はあまり詳しくないので, 変なことを言っていたら流して欲しいのですが, ループ内部で文字列の結合に足し算を使うのは効率がわるかったりしないのでしょうか?
There was a problem hiding this comment.
C++ は、文字列は mutable なので特に問題はないです。
Java、Python は immutable です。ちなみに、こういうのはよく知らない言語を触るときに一番初めに確認することの一つです。
| class Solution { | ||
| private: | ||
| string canonicalize(const string& email) { | ||
| int domain_start_position = email.rfind('@'); |
There was a problem hiding this comment.
@Ryotaro25
例えば、@がないような不正な入力が来た場合ってどうなりますか??
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題へのリンク
https://leetcode.com/problems/unique-email-addresses/description/
問題文(プレミアムの場合)
備考
次に解く問題の予告
387. First Unique Character in a String
https://leetcode.com/problems/first-unique-character-in-a-string/description/
フォルダ構成
LeetCodeの問題ごとにフォルダを作成します。
フォルダ内は、step1.cpp、step2.cpp、step3.cppとmemo.mdとなります。
memo.md内に各ステップで感じたことを追記します。