You are viewing a single comment's thread. Return to all comments →
#include
using namespace std; int main() { int n; cin>>n; int j , i = 0, cnt = 0;
string s; cin>>s;
for(j = 0; j < n; j++) { if(s[j] == 'U') { i = i + 1; if(i == 0) cnt++; } else if(s[j] == 'D') { i = i - 1; } }
cout<<cnt<<endl;
return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Valleys
You are viewing a single comment's thread. Return to all comments →
#include
include
using namespace std; int main() { int n; cin>>n; int j , i = 0, cnt = 0;
for(j = 0; j < n; j++) { if(s[j] == 'U') { i = i + 1; if(i == 0) cnt++; } else if(s[j] == 'D') { i = i - 1; } }
return 0; }