You are viewing a single comment's thread. Return to all comments →
Maybe help you with my solution:
static int countingValleys(int n, string s){
int numSeaLevel = 0; int numValleys = 0; for(int i=0;i<n;i++){ if(s[i] == 'U') numSeaLevel++; if(s[i] == 'D') numSeaLevel--; if(numSeaLevel==0 && s[i] == 'U'){ numValleys++; } } return numValleys; }
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 →
Maybe help you with my solution:
static int countingValleys(int n, string s){