Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d4e9393

Browse files
Create 07-03-2024.cpp
1 parent bac6a58 commit d4e9393

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

‎2024/03 - March/07-03-2024.cpp‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
3+
Author : Saransh Bangar
4+
Date : 07/03/2024
5+
Problem : Middle of the Linked List
6+
Difficulty : Easy
7+
Problem Link : https://leetcode.com/problems/middle-of-the-linked-list/description/
8+
Video Solution : NA
9+
10+
*/
11+
12+
13+
/**
14+
* Definition for singly-linked list.
15+
* struct ListNode {
16+
* int val;
17+
* ListNode *next;
18+
* ListNode() : val(0), next(nullptr) {}
19+
* ListNode(int x) : val(x), next(nullptr) {}
20+
* ListNode(int x, ListNode *next) : val(x), next(next) {}
21+
* };
22+
*/
23+
class Solution {
24+
public:
25+
ListNode* middleNode(ListNode* head)
26+
{
27+
ListNode* temp=head;
28+
int count=0;
29+
while (temp!=nullptr)
30+
{
31+
count++;
32+
temp=temp->next;
33+
}
34+
temp=head;
35+
int ans=count/2;
36+
while (ans)
37+
{
38+
temp=temp->next;
39+
ans--;
40+
}
41+
return temp;
42+
}
43+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /