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 86d8d44

Browse files
Merge pull request #17 from SaranshBangar/21/03/2024
Added LeetCode POTD (21/03/2024) solution in C++
2 parents ae0acfc + 70a2f24 commit 86d8d44

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
3+
Author : Saransh Bangar
4+
Date : 21/03/2024
5+
Problem : Reverse Linked List
6+
Difficulty : Easy
7+
Problem Link : https://leetcode.com/problems/reverse-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* reverseList(ListNode* head)
26+
{
27+
vector<int>help;
28+
ListNode* temp=head;
29+
while (temp!=nullptr)
30+
{
31+
help.push_back(temp->val);
32+
temp=temp->next;
33+
}
34+
temp=head;
35+
for (int i=help.size()-1;i>=0;i--)
36+
{
37+
temp->val=help[i];
38+
temp=temp->next;
39+
}
40+
return head;
41+
}
42+
};

0 commit comments

Comments
(0)

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