Conversation
| if sorted_nums1[index1] == sorted_nums2[index2]: | ||
| intersection_set.add(sorted_nums1[index1]) | ||
| index1 += 1 | ||
| index2 += 1 |
There was a problem hiding this comment.
ここのところ、同じものが見つかったら、同じ間ポインターを進めるようにすると、
intersection_set は list でいいですね。
https://discord.com/channels/1084280443945353267/1183683738635346001/1188897668827730010
| - これも片方がものすごく大きい場合どうするかに相当するとおもった。 | ||
| - https://github.com/hroc135/leetcode/pull/13/files | ||
| - pythonでも同様だが、[変数名に型の情報を不必要に入れるべきでない](https://google.github.io/styleguide/pyguide.html#2144-decision:~:text=names%20that%20needlessly%20include%20the%20type%20of%20the%20variable%20(for%20example%3A%20id_to_name_dict))というスタイルがある | ||
| - 今回はintersectionだけだと関数名と同じになるし、intersectionで想定するのが集合な気がするが、返り値はintersectionを保持するリストであるので、型名を入れることは許容範囲に感じた |
There was a problem hiding this comment.
関数名がintersectionであることから積集合を返すことが容易に想像できるので、ローカル変数名はresでもいいかもしれませんね
There was a problem hiding this comment.
res は略語ですが1000件ちょっと使われていますね。result のほうが5000件強で多いは多いです。
https://source.chromium.org/search?q=%22return%20res;%22%20filepath:.*%5C.cc$&sq=
https://source.chromium.org/search?q=%22return%20result;%22%20filepath:.*%5C.cc$&sq=
略語は避けるが慣習として明らかならよい、という話でしょう。
略語は略し方の不一致から、たまに気が付きにくい事故を起こします。たとえば、C++ で継承をしようとして Id と ID を間違えると、意図せずに新たに関数を定義してしまうことになります。
これ自体は C++11 からの override つけておきましょう、ですが、英単語を使うことで綴りが違うことへの違和感をより使おうという話です。
https://leetcode.com/problems/intersection-of-two-arrays/description/