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 eefe266

Browse files
24-03-2024
1 parent 86d8d44 commit eefe266

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
3+
Author : Manas Rawat
4+
Date : 23/03/2024
5+
Problem : Reorder List
6+
Difficulty : Medium
7+
Problem Link : https://leetcode.com/problems/reorder-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+
void reorderList(ListNode* head) {
26+
stack<ListNode*> s;
27+
ListNode* curr = head;
28+
while(curr){
29+
s.push(curr);
30+
curr = curr->next;
31+
}
32+
curr = head;
33+
unordered_map<ListNode*, bool> vis;
34+
while(true){
35+
ListNode* last = s.top();
36+
s.pop();
37+
ListNode* next = curr->next;
38+
vis[curr] = true;
39+
if(vis[last]){
40+
curr->next = NULL;
41+
break;
42+
}
43+
curr->next = last;
44+
vis[last] = true;
45+
curr = curr->next;
46+
if(vis[next]){
47+
curr->next = NULL;
48+
break;
49+
}
50+
curr->next = next;
51+
curr = curr->next;
52+
}
53+
}
54+
};

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
3+
Author : Manas Rawat
4+
Date : 24/03/2024
5+
Problem : Find the Duplicate Number
6+
Difficulty : Medium
7+
Problem Link : https://leetcode.com/problems/find-the-duplicate-number/description
8+
Video Solution : NA
9+
10+
*/
11+
12+
13+
class Solution {
14+
public:
15+
int findDuplicate(vector<int>& nums) {
16+
int n = nums.size();
17+
vector<int> f(n, 0);
18+
19+
for(auto i : nums) {
20+
if(f[i])
21+
return i;
22+
23+
++f[i];
24+
}
25+
26+
return 0;
27+
}
28+
};

0 commit comments

Comments
(0)

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