Conversation
| while (head != null) { | ||
| if (foundNode.contains(head)) { | ||
| return true; | ||
| } else { |
There was a problem hiding this comment.
else自体自分もあまり好まないので、気持ちわかります。
ただ、これを下げるというのはどうすべきでしょうか?
こんな形でしょうか?
boolean found = foundNode.contains(head);
if (found) {
//...
}
if (!found) {
// ...
}There was a problem hiding this comment.
if 節が return なので、
if (A) {
return X;
} else {
B;
}
C;
は
if (A) {
return X;
}
B;
C;
と同じですよね、ということです。
There was a problem hiding this comment.
あ、ごめんなさい。脳内試行でfast returnできない勘違いしてました。
| ListNode oneStepNode = head; | ||
| ListNode twoStepNode = head; | ||
|
|
||
| while ((twoStepNode != null) && (twoStepNode.next != null)) { |
There was a problem hiding this comment.
不要ですね。これはIDEに貼り付けた後に、つけた方がわかりやすいぞって一度適用して形確認したものです。
There was a problem hiding this comment.
本質ではないのですが、 IDE を使わずに練習したほうが良いかもしれません。面接本番では IDE 使えないと思いますので。
There was a problem hiding this comment.
IDE使ってないです。このmarkdownを書くときにleetcodeのエディターからコピーしており、そのときにヒントで出てたので、適用させてみたっていうところです。
| } | ||
| } | ||
|
|
||
| return false; |
There was a problem hiding this comment.
while (1) {
if (A) {return false;}
....
if (B) {return true;}
}
という構造ですね。
do while を使うなど色々な選択肢があることは頭においておきましょう。この構造を別のものと組み合わせるときに使うことになります。
https://leetcode.com/problems/linked-list-cycle/description/