Skip to content

Instantly share code, notes, and snippets.

@VallarasuS
Created March 11, 2023 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VallarasuS/007cbccad996c9db1daea6a3029a4601 to your computer and use it in GitHub Desktop.
Save VallarasuS/007cbccad996c9db1daea6a3029a4601 to your computer and use it in GitHub Desktop.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode middleNode(ListNode head) {
ListNode node = head;
ListNode[] nodes = new ListNode[100];
int index = 0;
while(node != null) {
nodes[index++] = node;
node = node.next;
}
return nodes[index / 2];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment