Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kabirrajsingh committed Jun 5, 2022
1 parent 3d7acb3 commit 9389e66
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 0 deletions.
26 changes: 26 additions & 0 deletions deleteanode.txt
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.
17 changes: 17 additions & 0 deletions majorityelement.txt
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;
}
14 changes: 14 additions & 0 deletions majorityelement2.txt
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;
}
32 changes: 32 additions & 0 deletions middleoflinkedlist.txt
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.
26 changes: 26 additions & 0 deletions validparanthesis.txt
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;
}

0 comments on commit 9389e66

Please sign in to comment.