Skip to content

Commit e2e0178

Browse files
committedJun 13, 2023
feat: update ts solution to lc problem: No.1941
1 parent c250f4b commit e2e0178

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed
 

‎solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,17 @@ function areOccurrencesEqual(s: string): boolean {
156156
}
157157
```
158158

159+
```ts
160+
function areOccurrencesEqual(s: string): boolean {
161+
const cnt: number[] = new Array(26).fill(0);
162+
for (const c of s) {
163+
++cnt[c.charCodeAt(0) - 'a'.charCodeAt(0)];
164+
}
165+
const x = cnt.find(v => v);
166+
return cnt.every(v => !v || v === x);
167+
}
168+
```
169+
159170
### **PHP**
160171

161172
```php

‎solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README_EN.md

+11
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ function areOccurrencesEqual(s: string): boolean {
140140
}
141141
```
142142

143+
```ts
144+
function areOccurrencesEqual(s: string): boolean {
145+
const cnt: number[] = new Array(26).fill(0);
146+
for (const c of s) {
147+
++cnt[c.charCodeAt(0) - 'a'.charCodeAt(0)];
148+
}
149+
const x = cnt.find(v => v);
150+
return cnt.every(v => !v || v === x);
151+
}
152+
```
153+
143154
### **PHP**
144155

145156
```php

‎solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/Solution.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ function areOccurrencesEqual(s: string): boolean {
33
for (const c of s) {
44
++cnt[c.charCodeAt(0) - 'a'.charCodeAt(0)];
55
}
6-
let x = 0;
7-
for (const v of cnt) {
8-
if (v) {
9-
if (!x) {
10-
x = v;
11-
} else if (x !== v) {
12-
return false;
13-
}
14-
}
15-
}
16-
return true;
6+
const x = cnt.find(v => v);
7+
return cnt.every(v => !v || v === x);
178
}

0 commit comments

Comments
 (0)
Please sign in to comment.