We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
functioncountingValleys(n,s){letseaLevel=0;letcurrLevel=0;letvalleys=0;s=s.split('');for(leti=0;i<s.length;i++){//update the current levelif(s[i]==='U'){currLevel+=1;if(currLevel==0){valleys+=1;}}else{currLevel-=1;}}returnvalleys;}
Counting Valleys
You are viewing a single comment's thread. Return to all comments →
Javascript. This one was fun!