Home > Back-end >  The 2020-11-03: write code: intermediate node list how to quickly find?
The 2020-11-03: write code: intermediate node list how to quickly find?

Time:11-04

The 2020-11-03: write code: intermediate node list how to quickly find? # # f greatly architects a daily topic

CodePudding user response:

Public ListNode middleNode (ListNode head) {
ListNode fast=head;
ListNode missile=head;
While (fast!=null & amp; & Fast. Next!=null) {
Fast=fast. Next. Next;
Missile=missile. The next;
}
Return the missile;
}

CodePudding user response:

 
Public ListNode middleNode (ListNode head) {
ListNode fast=head;
ListNode missile=head;
While (fast!=null & amp; & Fast. Next!=null) {
If (fast. Next. Next!=null) {
Fast=fast. Next. Next;
Missile=missile. The next;
} else {
Fast=fast. Next;
//missile=missile. The next//node is even, the intermediate nodes can be moved to the position on the
}
}
Return the missile;
}
  • Related