一、题目
Given a non-empty, singly linked list with head node head, return a middle node of linked list.
If there are two middle nodes, return the second middle node.
二、代码实现
/*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode(int x) { val = x; }* }*/
class Solution {
public ListNode middleNode(ListNode head) {
ListNode node = head;int len = getLength(head);for (int i = 0; i < len / 2; i++) {
node = node.next;}return node;}private int getLength(ListNode head){
int len = 0;while(head != null){
len ++;head = head.next;}return len;}
}