From 112812b870d5001bc3b5007249b17d5e0e7e9ff3 Mon Sep 17 00:00:00 2001 From: simran2607 <56145342+simran2607@users.noreply.github.com> Date: Wed, 21 Oct 2020 15:30:39 +0530 Subject: [PATCH 1/6] added leetcode problems #27 --- leetcode/cpp/Array/84.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 leetcode/cpp/Array/84.cpp diff --git a/leetcode/cpp/Array/84.cpp b/leetcode/cpp/Array/84.cpp new file mode 100644 index 00000000..8adfba47 --- /dev/null +++ b/leetcode/cpp/Array/84.cpp @@ -0,0 +1,24 @@ +class Solution { +public: +int largestRectangleArea(vector &A) { + int res = 0; + A.push_back(0); + + stack st; + + for(auto i=0; i= A[st.top()]) + st.push(i); + else + { + int j = st.top(); + st.pop(); + res = max(res, A[j]*(st.empty() ? i : i - st.top() - 1)); + i--; + } + } + + return res; +} +}; From 77167b051cc12e73128e003a0e84b0c350c23164 Mon Sep 17 00:00:00 2001 From: simran2607 <56145342+simran2607@users.noreply.github.com> Date: Wed, 21 Oct 2020 15:36:09 +0530 Subject: [PATCH 2/6] added leetcode problems #27 --- leetcode/cpp/Stacks/155.cpp | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 leetcode/cpp/Stacks/155.cpp diff --git a/leetcode/cpp/Stacks/155.cpp b/leetcode/cpp/Stacks/155.cpp new file mode 100644 index 00000000..d389f30c --- /dev/null +++ b/leetcode/cpp/Stacks/155.cpp @@ -0,0 +1,49 @@ +class MinStack { +public: + /** initialize your data structure here. */ + MinStack() { + + } + stack st; + stack min_st; + void push(int x) { + st.push(x); + int val =x; + if(min_st.size()>0 && min_st.top()push(x); + * obj->pop(); + * int param_3 = obj->top(); + * int param_4 = obj->getMin(); + */ From adc041d9436aefea794a450602999fb77a8a4f88 Mon Sep 17 00:00:00 2001 From: simran2607 <56145342+simran2607@users.noreply.github.com> Date: Wed, 21 Oct 2020 15:47:47 +0530 Subject: [PATCH 3/6] added leetcode problems #27 --- leetcode/cpp/Array/31.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 leetcode/cpp/Array/31.cpp diff --git a/leetcode/cpp/Array/31.cpp b/leetcode/cpp/Array/31.cpp new file mode 100644 index 00000000..a8b3267d --- /dev/null +++ b/leetcode/cpp/Array/31.cpp @@ -0,0 +1,26 @@ +class Solution { +public: + void nextPermutation(vector& A) { + int i,j; + int n = A.size(); + for(i = n - 2;i >= 0;i --) + { + if(A[i] < A[i + 1]) + break; + } + if(i == -1) + { + reverse(A.begin(),A.end()); + return ; + } + + for(j = n - 1;j > i;j --) + { + if(A[j] > A[i]) + break; + } + swap(A[j],A[i]); + reverse(A.begin() + i + 1,A.end()); + return ; + } +}; From 3c5eaae7cfed32297619d5f1112860cf4172a922 Mon Sep 17 00:00:00 2001 From: simran2607 <56145342+simran2607@users.noreply.github.com> Date: Wed, 21 Oct 2020 16:00:18 +0530 Subject: [PATCH 4/6] added leetcode problems --- leetcode/cpp/Two Pointer/16.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 leetcode/cpp/Two Pointer/16.cpp diff --git a/leetcode/cpp/Two Pointer/16.cpp b/leetcode/cpp/Two Pointer/16.cpp new file mode 100644 index 00000000..3c1583d4 --- /dev/null +++ b/leetcode/cpp/Two Pointer/16.cpp @@ -0,0 +1,31 @@ +class Solution { +public: + int threeSumClosest(vector& A, int target) { + sort(A.begin(),A.end()); + int f,s,t; + int res=0; + int min_diff =INT_MAX; + for(f=0;ftarget) + t--; + else if(sum Date: Wed, 21 Oct 2020 16:00:47 +0530 Subject: [PATCH 5/6] added leetcode problems --- 16.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 16.cpp diff --git a/16.cpp b/16.cpp new file mode 100644 index 00000000..3c1583d4 --- /dev/null +++ b/16.cpp @@ -0,0 +1,31 @@ +class Solution { +public: + int threeSumClosest(vector& A, int target) { + sort(A.begin(),A.end()); + int f,s,t; + int res=0; + int min_diff =INT_MAX; + for(f=0;ftarget) + t--; + else if(sum Date: Wed, 21 Oct 2020 16:04:07 +0530 Subject: [PATCH 6/6] added leetcode problems #27 --- leetcode/cpp/Two Pointer/75.cpp | 43 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/leetcode/cpp/Two Pointer/75.cpp b/leetcode/cpp/Two Pointer/75.cpp index 1e5d7dfe..5141004f 100644 --- a/leetcode/cpp/Two Pointer/75.cpp +++ b/leetcode/cpp/Two Pointer/75.cpp @@ -1,22 +1,21 @@ -class Solution { -public: - void sortColors(vector& nums) { - int low=0,mid=0,high=nums.size()-1; - while(mid<=high){ - - if(nums[mid]==0) - { - swap(nums[low],nums[mid]); - low++,mid++; - } - else if(nums[mid]==1) - { - mid++; - } - else{ - swap(nums[mid],nums[high]); - high--; - } - } - } -}; +class Solution { +public: + void sortColors(vector& A) { + int count_0=0,count_1=0,count_2=0; + for(int i=0;i