Skip to content

Commit dc54a6f

Browse files
author
1999code
committed
Added cpp program
1 parent 4c8a600 commit dc54a6f

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

leetcode/Valid Parenthesis.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
class Solution {
2+
public:
3+
bool isValid(string expression) {
4+
stack<char>s;
5+
for(int i=0;i<expression.length();i++){
6+
char ch = expression[i];
7+
//opening parantheses push
8+
if(ch=='(' || ch=='{' || ch=='[')
9+
{
10+
s.push(ch);
11+
12+
}
13+
//for close parantheses check on top and pop
14+
else
15+
{
16+
if(!s.empty()) {
17+
char top=s.top();
18+
19+
20+
if( ch==')' && top=='('
21+
||
22+
ch=='}' && top=='{'
23+
||
24+
ch==']' && top=='[')
25+
{
26+
s.pop();
27+
}
28+
else
29+
{
30+
return false;
31+
}
32+
}
33+
else {
34+
return false;
35+
}
36+
37+
38+
}
39+
40+
41+
42+
}
43+
if(s.empty())
44+
return true;
45+
46+
47+
else
48+
return false;
49+
}
50+
};

leetcode/c_cpp_properties.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "windows-gcc-x86",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"compilerPath": "C:/MinGW/bin/gcc.exe",
9+
"cStandard": "${default}",
10+
"cppStandard": "${default}",
11+
"intelliSenseMode": "windows-gcc-x86",
12+
"compilerArgs": [
13+
""
14+
]
15+
}
16+
],
17+
"version": 4
18+
}

0 commit comments

Comments
 (0)