diff --git "a/problems/1002.\346\237\245\346\211\276\345\270\270\347\224\250\345\255\227\347\254\246.md" "b/problems/1002.\346\237\245\346\211\276\345\270\270\347\224\250\345\255\227\347\254\246.md" index 08e7ec3d8e..7c5566d333 100644 --- "a/problems/1002.\346\237\245\346\211\276\345\270\270\347\224\250\345\255\227\347\254\246.md" +++ "b/problems/1002.\346\237\245\346\211\276\345\270\270\347\224\250\345\255\227\347\254\246.md" @@ -58,7 +58,7 @@ words[i] 由小写英文字母组成 先统计第一个字符串所有字符出现的次数,代码如下: -``` +```cpp int hash[26] = {0}; // 用来统计所有字符串里字符出现的最小频率 for (int i = 0; i < A[0].size(); i++) { // 用第一个字符串给hash初始化 hash[A[0][i] - 'a']++; @@ -71,7 +71,7 @@ for (int i = 0; i < A[0].size(); i++) { // 用第一个字符串给hash初始化 代码如下: -``` +```cpp int hashOtherStr[26] = {0}; // 统计除第一个字符串外字符的出现频率 for (int i = 1; i < A.size(); i++) { memset(hashOtherStr, 0, 26 * sizeof(int)); @@ -84,11 +84,11 @@ for (int i = 1; i < A.size(); i++) { } } ``` -此时hash里统计着字符在所有字符串里出现的最小次数,那么把hash转正题目要求的输出格式就可以了。 +此时hash里统计着字符在所有字符串里出现的最小次数,那么把hash转成题目要求的输出格式就可以了。 代码如下: -``` +```cpp // 将hash统计的字符次数,转成输出形式 for (int i = 0; i < 26; i++) { while (hash[i] != 0) { // 注意这里是while,多个重复的字符