From c07a26504df37d8f4e01ea363c71c5f09f2fa1aa Mon Sep 17 00:00:00 2001 From: shubhamkumar47 Date: Tue, 11 Oct 2022 02:46:23 +0530 Subject: [PATCH 1/3] C++ Solution of 48.Rotate_image --- Leetcode-Medium/48-Rotate_IMAGE_C++.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Leetcode-Medium/48-Rotate_IMAGE_C++.cpp diff --git a/Leetcode-Medium/48-Rotate_IMAGE_C++.cpp b/Leetcode-Medium/48-Rotate_IMAGE_C++.cpp new file mode 100644 index 0000000..00e7ade --- /dev/null +++ b/Leetcode-Medium/48-Rotate_IMAGE_C++.cpp @@ -0,0 +1,17 @@ +class Solution { +public: + void rotate(vector>& matrix) { + int n= matrix.size(); + for(int i=0; i Date: Tue, 11 Oct 2022 02:58:29 +0530 Subject: [PATCH 2/3] assign 48,Rotate_image in right folder --- .../32.cpp_Longest Valid Parentheses.cpp | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Leetcode-Easy/32.cpp_Longest Valid Parentheses.cpp diff --git a/Leetcode-Easy/32.cpp_Longest Valid Parentheses.cpp b/Leetcode-Easy/32.cpp_Longest Valid Parentheses.cpp new file mode 100644 index 0000000..4c77da8 --- /dev/null +++ b/Leetcode-Easy/32.cpp_Longest Valid Parentheses.cpp @@ -0,0 +1,58 @@ +/*Explanation -: + +Create an empty stack and push -1 to it. +The first element of the stack is used +to provide a base for the next valid string. + +Initialize result as 0. + +If the character is '(' i.e. str[i] == '('), +push index'i' to the stack. + +Else (if the character is ')') +a) Pop an item from the stack (Most of the +time an opening bracket) + +b) If the stack is not empty, then find the +length of current valid substring by taking +the difference between the current index and +top of the stack. If current length is more +than the result, then update the result. + +c) If the stack is empty, push the current index +as a base for the next valid substring. + +Return result. + +If still not able to visualize, Try to do a dry run with pen/paper. + +C++ Code -: +*/ +class Solution { +public: + int longestValidParentheses(string s) + { + int n=s.length(); + int result=0; + stack st; + st.push(-1); + for(int i=0;i Date: Tue, 11 Oct 2022 03:00:40 +0530 Subject: [PATCH 3/3] 32.cpp_longest Valid parenthesis c++ solution --- Leetcode-Easy/32.cpp_Longest Valid Parentheses.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Leetcode-Easy/32.cpp_Longest Valid Parentheses.cpp b/Leetcode-Easy/32.cpp_Longest Valid Parentheses.cpp index 4c77da8..f9ddc37 100644 --- a/Leetcode-Easy/32.cpp_Longest Valid Parentheses.cpp +++ b/Leetcode-Easy/32.cpp_Longest Valid Parentheses.cpp @@ -3,7 +3,6 @@ Create an empty stack and push -1 to it. The first element of the stack is used to provide a base for the next valid string. - Initialize result as 0. If the character is '(' i.e. str[i] == '('),