mirror of
https://git.wolves.top/wolves/leetcode.git
synced 2025-11-04 17:26:32 +08:00
init
This commit is contained in:
33
we/24-2.h
Normal file
33
we/24-2.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char* destar(char *str){
|
||||
int length = strlen(str);
|
||||
char *ret = (char *)malloc(sizeof(char)*length);
|
||||
if(ret == NULL){
|
||||
return "error";
|
||||
}
|
||||
int left=0,right=length-1;
|
||||
while (str[left++]=='*');
|
||||
while (str[right--]=='*');
|
||||
strncpy(ret,str,left);
|
||||
char temp;
|
||||
int i = left;
|
||||
while (left<=right)
|
||||
{
|
||||
temp = str[left++];
|
||||
if((temp >= 'a' && temp <= 'z') ||
|
||||
(temp >= 'A' && temp <= 'Z')) {
|
||||
ret[i++] = temp;
|
||||
}else if(temp=='*'){
|
||||
continue;
|
||||
}else{
|
||||
free(ret);
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
strncpy(ret+i,str+right+1,length - (right + 1));
|
||||
ret[length - (left - i)] = '\0';
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user