• + 0 comments

    Here is my c++ solution you can find the video here : https://youtu.be/fgJ-i8RJ1Qw

    int countingValleys(int steps, string path) {
        int res = 0, level = 0;
        for(char c : path){
            if(c == 'U'){
                level++;
                if(level == 0) res ++;
            }
            else level--;
        }
        return res;
    }