Website Summary Files Commits Branches @commit @diff @stats
path: root / Practicum / pract05 / solutions / Task02.cpp
diff options
context:
space:
mode:
Commitb445b1b7522eb8862dffd027f391ee224e25b241 (patch)
Author
 Desislava Shunina <115353472+desiish@users.noreply.github.com>
2024-11-05 17:13:22 +0200
Committer
 GitHub <noreply@github.com>
2024-11-05 17:13:22 +0200
Filesaceefa96509b5086609a11cb51a40ad35def80d3 /Practicum/pract05/solutions/Task02.cpp
Data-structures-and-algorithms-b445b1b7522eb8862dffd027f391ee224e25b241.tar
Data-structures-and-algorithms-b445b1b7522eb8862dffd027f391ee224e25b241.tar.gz
Data-structures-and-algorithms-b445b1b7522eb8862dffd027f391ee224e25b241.zip
Parentf281f4124941da875a81df70b9b91b6eaf529434 (diff)
add second task solution
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;
+ }
+};