Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int lengthOfLastWord(string s) {
- stack<char>st;
- int count=0;
- for(int i=0;i<s.length();i++)
- {
- st.push(s[i]);
- }
- while(st.top()==' ')
- {
- st.pop();
- }
- while(!st.empty() && st.top()!=' ')
- {
- count++;
- st.pop();
- }
- return count;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment