What is the use of s[top]='#' here

//program to find valid parenthesis in a string
//https://leetcode.com/problems/valid-parentheses/
bool isValid(char * str){
int top=-1;
char S[100000];
int i;
for(i=0;str[i];i++)
{
if(str[i]==’(’||str[i]==’[’||str[i]==’{’)
S[++top]=str[i];
else
{
if(top<0) return false;
switch(str[i])
{
case ‘)’ :
if(S[top]==’(’)
S[top–]=’#’;
else return false;
break;
case ‘}’ :
if(S[top]==’{’)
S[top–]=’#’;
else return false;
break;
case ‘]’ :
if(S[top]==’[’)
S[top–]=’#’;
else return false;
break;
}
}
}
return top==-1?true:false;
}

Hey @negia :wave: ,
That ‘#’ is used for marking the character as visited, so that it never takes that character back again.