Lect.22 Array String (Leetcode Question) [CodeHelp-DSA-Busted-Series] - TagMerge

Lect.22 Array String (Leetcode Question) [CodeHelp-DSA-Busted-Series]

Justin-royAsked 4 months ago

Video Timestamp - 55:15 Leetcode Question No- 151. Reverse Words in a String.

Bhaiya Ur Telling Reverse String But There Some Certain Condition have a look….

Here The My Solved Problem Code ..

class Solution { public: string reverseWords(string s) { string ans; stack stk; int i = 0; while(i < s.size()) { string temp; while(i < s.size() && s[i] == ' ') ++i; while(i < s.size() && s[i] != ' ') { temp.push_back(s[i++]); } if(temp.size() > 0) stk.push(temp); } int j=0; while(!stk.empty()) { ans += stk.top(); stk.pop(); if(!stk.empty()) ans += ' '; } return ans; } };

Source: link

supersaint7780Answered 4 months ago

For this purpose either create a new pull request or suggest an edit to original code. The create an issue feature is not for this purpose.

Recent Issues

    Programming Languages