3330. Find the Original Typed String I || Leetcode Daily Challenge July || potd

preview_player
Показать описание
Check out the video of today's Daily challenge on Leetcode!
Subscribe for more cool stuffs.

Code Solution in text: See comments

Hi! I'm Mitadru Datta, IIT KGP'25. I love breaking down complex problems in simple words and hence the vision of this channel. Follow my channel with more upcoming content on interview experiences of various companies and in depth AI and DSA prep.

Hope you have an easy day ahead :)

#leetcode
#leetcodedaily
#leetcodedailychallenge
#dsa #potd
Рекомендации по теме
Комментарии
Автор

int ans = 1, n = word.size();
char p = word[0];
int cnt = 1;
for(int i=1;i<n;i++){
while(word[i]==p){
i++; cnt++;
}
ans += (cnt-1); cnt = 1;
p = word[i];
} // O(n) -> visiting every char only once!
return ans;

eyeonaianddsa
join shbcf.ru