Answers for "counting valleys hackerrank solution in c++"

C++
0

counting valleys hackerrank solution in c++

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n,updown = 0,res = 0;
    char c;
    cin >> n;
    
    for(int i = 0; i++ < n;){
        cin >> c;
        if(c == 'U')updown++;
        else updown--;
        if(updown == 0 && c == 'U')res++;
    }
    cout << res << endl;
    return 0;
}
Posted by: Guest on June-26-2020

Code answers related to "counting valleys hackerrank solution in c++"

Browse Popular Code Answers by Language