Leetcode error: AddressSanitizer:DEADLYSIGNAL [How to Solve]

leetcode error:

AddressSanitizer:DEADLYSIGNAL ================================================================= ==43==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x00000034ca17 bp 0x7ffe82f08070 sp 0x7ffe82f07f40 T0) ==43==The signal is caused by a READ memory access. ==43==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used. #3 0x7f952a7800b2 (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) AddressSanitizer can not provide additional info. ==43==ABORTING

As you can see, the unknown address was accessed.
Reason:
The code accesses the top element of the stack for an empty stack

else if(s[i] == '}')
{
    if(st.top() == '{')
    {
       st.pop();
    }else
    {
       return false;
    }
}

Solution:

Just join the blank judgment

else if(s[i] == '}')
{
    if(!st.empty() && st.top() == '{')
    {
        st.pop();
    }else
    {
        return false;
    }
}

Read More: