Remove All Spaces

Given a string s, remove every ASCII space character (' ') and return the resulting string. Preserve the relative order of all other characters. The returned string may be empty.

Example 1:

Input: s = "Hello World"

Output: "HelloWorld"

Explanation: Remove the space between words.

Example 2:

Input: s = " a b c "

Output: "abc"

Explanation: Remove leading, trailing, and repeated spaces.

Still unsure what the problem is asking ?

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

Example 3:

Input: s = " "

Output: ""

Explanation: All characters are spaces, so the result is empty.

Constraints:

  • 1 <= s.length() <= 100000
  • Sum of lengths of all strings in one hidden test file <= 100000
  • s contains printable ASCII characters, including spaces.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
string removeSpaces(string s) {
// Write your code here
return "";
}
};
 
Test Case

Input:

S