Website Summary Files Commits Branches @commit @diff @stats
path: root / Practicum / pract05 / solutions / Task02.cpp
diff options
context:
space:
mode:
1 files changed, 16 insertions, 0 deletions
-rw-r--r--Practicum/pract05/solutions/Task02.cpp16
diff --git a/Practicum/pract05/solutions/Task02.cpp b/Practicum/pract05/solutions/Task02.cpp
new file mode 100644
index 0000000..4905d58
--- /dev/null
+++ b/Practicum/pract05/solutions/Task02.cpp
@@ -0,0 +1,16 @@
+class Solution {
+public:
+ ListNode* middleNode(ListNode* head) {
+ if(!head)
+ return nullptr;
+
+ ListNode* middle = head;
+ ListNode* end = head;
+
+ while(end != nullptr && end->next != nullptr) {
+ middle = middle->next;
+ end = end->next->next;
+ }
+ return middle;
+ }
+};