Skip to content

Commit

Permalink
1002.查找常用字符:优化排版,修改错别字
Browse files Browse the repository at this point in the history
  • Loading branch information
bqlin committed Jan 8, 2022
1 parent c9fc0cb commit 59b38a9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions problems/1002.查找常用字符.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']++;
Expand All @@ -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));
Expand All @@ -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,多个重复的字符
Expand Down

0 comments on commit 59b38a9

Please sign in to comment.