• + 11 comments

    can any one can write simpler than this "python" land=0

    valley=0
    
    for i in s:
    
        if i=='U':
    
            land+=1
    
        if i=='D':
    
            land+=-1
    
        if land==0 and i=='U':
    
           valley+=1
    
    return valley