• + 0 comments

    had similar idea in python

    def countingValleys(n, s):
        g=0
        count=0
        for i in s:
            if i =='U':
                g+=1
            else:
                g-=1
            if g==0 and i=='U':
                count+=1
        return count