From aa8d2bbf6ee5ea1dd33617bc275e854fc0a899e4 Mon Sep 17 00:00:00 2001 From: Nofeboy <110103302+nofeboy@users.noreply.github.com> Date: Wed, 29 Mar 2023 16:28:31 +0900 Subject: [PATCH] =?UTF-8?q?876=EB=B2=88=20=EC=9A=B0=EC=88=98=20=ED=92=80?= =?UTF-8?q?=EC=9D=B4=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 876. Middle of the Linked List/README.md | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 876. Middle of the Linked List/README.md diff --git a/876. Middle of the Linked List/README.md b/876. Middle of the Linked List/README.md new file mode 100644 index 0000000..b6d7375 --- /dev/null +++ b/876. Middle of the Linked List/README.md @@ -0,0 +1,27 @@ +# 876. Middle of the Linked List + +[Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/) + +## 장세현 - 2023.03.28 + +1. 두 개의 노드 fast와 slow 생성 (토끼와 거북이) +2. fast는 두 번씩 움직이고, slow는 한 번씩 움직이는 걸 반복 +3. fast의 이동이 끝났다면, slow를 return + +```java +class Solution { + public ListNode middleNode(ListNode head){ + ListNode fast = head; + ListNode slow = head; + + while (fast != null && fast.next != null){ + slow=slow.next; + fast=fast.next.next; + } + + return slow; + } +} +``` + +---