Conversation
fhiyo
reviewed
Jun 13, 2024
Comment on lines
+4
to
+7
| set<int> unique_number1; | ||
| for (auto i : number1) { | ||
| unique_number1.insert(i); | ||
| } |
There was a problem hiding this comment.
Suggested change
| set<int> unique_number1; | |
| for (auto i : number1) { | |
| unique_number1.insert(i); | |
| } | |
| set<int> unique_number1(number1.begin(), number1.end()); |
こうも書けますね
https://en.cppreference.com/w/cpp/container/set/set
Owner
Author
There was a problem hiding this comment.
@fhiyo
レビューありがとうございます。
この書き方知りませんでした。こちらの方がスッキリかけますね。step4.cppに追加しました。
liquo-rice
reviewed
Jun 13, 2024
| @@ -0,0 +1,35 @@ | |||
| ## ステップ1 | |||
There was a problem hiding this comment.
set, unordered_set, map, unordered_mapの違いがあまりよく分かっていないような印象を受けました。
There was a problem hiding this comment.
oda
reviewed
Jun 13, 2024
|
|
||
| int i = 0; | ||
| int j = 0; | ||
| int current_numbebr = -1; |
There was a problem hiding this comment.
-1 がないことを使うのは、状況からそうしてもいいことが明らかな場合はありますが、一応そうではない場合も考えたいですね。
私は、重複削除を二重ループにするとかが好みです。
Owner
Author
There was a problem hiding this comment.
@oda
レビューありがとうございます。
number1とnumber2が同じになった場合に現在の数字をcurrent_numberに設定しました。またこのタイミングでループを追加し重複がなくなるまでインクリメントするようにしました。
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/intersection-of-two-arrays/description/
問題文(プレミアムの場合)
備考
次に解く問題の予告
Unique Email Addresses
フォルダ構成
LeetCodeの問題ごとにフォルダを作成します。
フォルダ内は、step1.cpp、step2.cpp、step3.cppとmemo.mdと
merge_sort_like.cppとset_intersection.cppになります。
memo.md内に各ステップで感じたことを追記します。