-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d7acb3
commit 9389e66
Showing
8 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <bits/stdc++.h> | ||
/**************************************************************** | ||
|
||
Following is the class structure of the LinkedListNode class: | ||
|
||
template <typename T> | ||
class LinkedListNode | ||
{ | ||
public: | ||
T data; | ||
LinkedListNode<T> *next; | ||
LinkedListNode(T data) | ||
{ | ||
this->data = data; | ||
this->next = NULL; | ||
} | ||
}; | ||
|
||
*****************************************************************/ | ||
|
||
void deleteNode(LinkedListNode<int> * node) { | ||
// Write your code here. | ||
LinkedListNode<int> *temp=node; | ||
temp->data=temp->next->data; | ||
temp->next=temp->next->next; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <bits/stdc++.h> | ||
int findMajorityElement(int arr[], int n) { | ||
// Write your code here. | ||
int limit; | ||
if(n%2==0){limit=n/2+1;} | ||
|
||
else{limit=(n/2)+1;} | ||
// cout<<limit<<endl; | ||
map<int,int> hash; | ||
for(int i=0;i<n;i++){ | ||
hash[arr[i]]++; | ||
} | ||
for(auto i:hash){ | ||
if(i.second>=limit){return i.first;} | ||
} | ||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <bits/stdc++.h> | ||
vector<int> majorityElementII(vector<int> &arr) | ||
{ | ||
// Write your code here. | ||
vector<int> result; | ||
map<int,int> hash; | ||
for(int i=0;i<arr.size();i++){ | ||
hash[arr[i]]++; | ||
} | ||
for(auto i:hash){ | ||
if(i.second>arr.size()/3){result.push_back(i.first);} | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <bits/stdc++.h> | ||
/**************************************************************** | ||
|
||
Following is the class structure of the Node class: | ||
|
||
class Node | ||
{ | ||
public: | ||
int data; | ||
Node *next; | ||
Node(int data) | ||
{ | ||
this->data = data; | ||
this->next = NULL; | ||
} | ||
}; | ||
|
||
*****************************************************************/ | ||
|
||
Node *findMiddle(Node *head) { | ||
// Write your code here | ||
int size=0; | ||
Node* temp=head; | ||
while(temp){size++;temp=temp->next;} | ||
temp=head; | ||
for(int i=0;i<size/2;i++){ | ||
// cout<<temp->data<<endl; | ||
temp=temp->next; | ||
} | ||
|
||
return temp; | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include<iostream> | ||
bool isValidParenthesis(string expression) | ||
{ | ||
// Write your code here. | ||
stack<char> st; | ||
for(auto i:expression){ | ||
if(i=='(' || i=='{' || i=='['){ | ||
// cout<<"hey1"<<endl; | ||
st.push(i); | ||
}else{ | ||
if(st.empty()){ | ||
// cout<<"hey3"<<endl; | ||
return false;} | ||
else{ | ||
if((st.top()=='(' && i==')') || (st.top()=='{' && i=='}') || (st.top()=='[' && i==']')){ | ||
// cout<<"hey2"<<endl; | ||
st.pop(); | ||
}else{return false;} | ||
} | ||
} | ||
|
||
} | ||
if(st.empty()){return true;} | ||
// cout<<"here2"<<endl; | ||
return false; | ||
} |