1010. Remove Spaces from a String

Given a string str, write a program to remove all whitespaces from the string and return the modified string.

Example 1:

Input: str = "Take you forward"

Output: "Takeyouforward"

Explanation: All spaces are removed.

Example 2:

Input: str = "How are you doing"

Output: "Howareyoudoing"

Explanation: All spaces removed from the string.

Now Your Turn!

Pick the correct output for the given input

Input: str = "  Open  AI GPT  "

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= str.length <= 105
  • str may contain uppercase/lowercase letters, digits, special characters, and space ' '
  • You must preserve the order of characters.
0
class Solution {
public:
string removeSpaces(const string& str) {
// Your code goes here
}
};
 
Test Case

Input:

Str