res to 0 to store the number of balanced substrings found.cnt to 0 to keep track of the balance between 'L' and 'R' characters.c in the string s.
c is 'L', increment cnt.c is 'R', decrement cnt.cnt becomes 0, it means we have found a balanced substring, so increment res.res.