카타 8급 Remove String Spaces

1 C[ | ]

#include <stdlib.h>
char *no_space(char *strin) {
  int len = strlen(strin);
  char *res = malloc(len);
  int offset = 0;
  for(int i=0; i<len; i++) {
    while(strin[i+offset]==' ') offset++;
    res[i] = strin[i+offset];
  }
  return res;
}
#include <stdlib.h>
char *no_space(char *strin) {
  char *res = malloc(strlen(strin)+1);
  char *p = res;  
  while(*strin) {
    if(*strin != ' ') *p++ = *strin;
    strin++;
  }
  *p='\0';
  return res;
}

2 C++[ | ]

std::string no_space(std::string x)
{
  x.erase(std::remove(x.begin(), x.end(), ' '), x.end());
  return x;
}
std::string no_space(std::string x)
{    
    std::string temp="";
    for(int i = 0;i<x.size();i++){
      if(x[i]!=' ')
        temp+=x[i];
    }
    return temp;
}

3 Kotlin[ | ]

fun noSpace(x: String) = x.replace("\\s+".toRegex(), "")
fun noSpace(x: String) = x.replace(Regex("""\s"""), "")
fun noSpace(x: String) = x.replace(" ", "")
fun noSpace(x: String) = x.filterNot { it.isWhitespace() }
fun noSpace(x: String) = x.filterNot(Char::isWhitespace)

4 PHP[ | ]

function no_space(string $s): string {
  return str_replace(' ','',$s);
}
function no_space(string $s): string {
  return preg_replace("/\s/", "", $s);
}

5 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}