Skip to content

15. 3Sum#4

Open
yamashita-ki wants to merge 2 commits intomainfrom
leetcode/15
Open

15. 3Sum#4
yamashita-ki wants to merge 2 commits intomainfrom
leetcode/15

Conversation

@yamashita-ki
Copy link
Owner

@yamashita-ki
Copy link
Owner Author

hoge

@yamashita-ki yamashita-ki changed the title 3Sum 15. 3Sum Sep 13, 2025
Copy link

@huyfififi huyfififi left a comment

Choose a reason for hiding this comment

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

良いと思います 👍 3重ループも、two pointersを応用する方法も解法として納得感がありました!

int length = nums.length;
Set<List<Integer>> ans = new HashSet<>();
Arrays.sort(nums);
for(int i = 0; i<length-2;i++){

Choose a reason for hiding this comment

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

step 2, 3 では改善されているのですが、コードスタイルの揺れ (operatorの周りのスペースや;の後のスペース) が読んでいて少し気になりました。

Copy link
Owner Author

Choose a reason for hiding this comment

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

ご確認いただきありがとうございます!
短時間で解くことのみに集中してFormatできていなかったので次回に生かしたいと思います 🙇

List<List<Integer>> res = new ArrayList<>();

for (int i = 0; i < nums.length; i++) {
if (nums[i] > 0) break;

Choose a reason for hiding this comment

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

Javaのsyntaxや業界的なスタンダードには明るくないのですが、勉強会に参加されている方々のC++のコードを読んでいると、ぶら下がりifは明確に避けられていると感じますね、事故が起きやすいので。使用するにしても、一定数の方々が忌避感を持つパターンであるというのは意識しておいても損はないと思います!(確かDiscord内や典型コメント集で検索するといくらかヒットした記憶があります。)

ちなみに先日、Odaさんがぶら下がりifによる事故の例がDiscordで共有されていました。
https://discord.com/channels/1084280443945353267/1084283898617417748/1370794488607543306

Copy link
Owner Author

Choose a reason for hiding this comment

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

リンクの共有までありがとうございます。

ぶら下がりifは明確に避けられていると感じますね、事故が起きやすいので。使用するにしても、一定数の方々が忌避感を持つパターンであるというのは意識しておいても損はないと思います!

ぶら下がりifが事故が起きやすいという認識を持てていなかったです。
調べたところJavaでも同じような事故が起きているとのことだったので今後は避けようと思います 🙇

int l = i + 1;
int r = numLength - 1;
while (l < r) {
int curSum = nums[i] + nums[r] + nums[l];

Choose a reason for hiding this comment

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

一度に着目しているsumはこの変数だけなので、現在着目しているという意図であれば、"current" は情報を追加せず不要かと思います。また、私もまだコードを読んで感覚を養っている途中なのですが、現在着目しているという意図での"current"は、実際の現場との用法からズレたものである...と聞いたことがあります。
典型コメント集にも載っていたと思うので、そちらを参照していただくと良いかと思います。
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.fcs3httrll4l

Copy link
Owner Author

Choose a reason for hiding this comment

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

一度に着目しているsumはこの変数だけなので、現在着目しているという意図であれば、"current" は情報を追加せず不要かと思います。

確かに、sumが変数名に含まれるものは1つしかないためcurrentという情報は不要ですね。
納得感ありましたmm

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.

2 participants