# 剑指 Offer 05. 替换空格

## 代码

``````char* replaceSpace(char* s)
{
if(NULL == s) return NULL;

//统计空格个数
int count = 0;
for (int i = 0; i < strlen(s); ++i)
{
if (s[i] == ' ')
count++;
}
//申请新空间
char* ans = (char*)malloc(sizeof(char) * strlen(s) + count * 2 + 1);

int i = 0, j = 0;
for (i; i < strlen(s); ++i, ++j)
{
ans[j] = s[i];
if (s[i] == ' ')
{
ans[j++] = '%';
ans[j++] = '2';
ans[j] = '0';
}
}
ans[j] = '';
return ans;
}
``````

# 面试题 10.05. 稀疏数组搜索

## 代码

``````int findString(char** words, int wordsSize, char* s)
{
for (int i = 0; i < wordsSize; ++i)
{
if (strcmp(s, words[i]) == 0)
{
return i;
}
}
return -1;
}
``````

# 1309. 解码字母到整数映射

## 代码

``````char * freqAlphabets(char * s)
{
char* str = (char*)malloc(sizeof(char) * strlen(s) + 1);
int strSize = 0;

for (int i = 0; i < strlen(s); ++i)
{
if (i + 2 < strlen(s) && s[i + 2] == '#')
{
str[strSize++] = ((s[i] - '0') * 10 + (s[i + 1] - '1') + 'a');
i += 2;
}
else
{
str[strSize++] = s[i] - '1' + 'a';
}
}
str[strSize] = '';
return str;
}
``````

# 1967. 作为子字符串出现在单词中的字符串数目

## 分析

``````char* strstr(char* str1, char* str2);
``````

## 代码

``````int numOfStrings(char ** patterns, int patternsSize, char * word)
{
int count = 0;
for (int i = 0; i < patternsSize; ++i)
{
if (strstr(word, patterns[i]))
{
count++;
}
}
return count;
}
``````

THE END