Skip to content

Commit c453875

Browse files
committed
feat: add solutions to lc problem: No.1838
No.1838.Frequency of the Most Frequent Element
1 parent 8b477c6 commit c453875

File tree

10 files changed

+332
-249
lines changed

10 files changed

+332
-249
lines changed

solution/1200-1299/1248.Count Number of Nice Subarrays/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,26 @@ func numberOfSubarrays(nums []int, k int) (ans int) {
137137
}
138138
```
139139

140+
### **TypeScript**
141+
142+
```ts
143+
function numberOfSubarrays(nums: number[], k: number): number {
144+
const n = nums.length;
145+
const cnt = new Array(n + 1).fill(0);
146+
cnt[0] = 1;
147+
let ans = 0;
148+
let t = 0;
149+
for (const v of nums) {
150+
t += v & 1;
151+
if (t - k >= 0) {
152+
ans += cnt[t - k];
153+
}
154+
cnt[t] += 1;
155+
}
156+
return ans;
157+
}
158+
```
159+
140160
### **...**
141161

142162
```

solution/1200-1299/1248.Count Number of Nice Subarrays/README_EN.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ func numberOfSubarrays(nums []int, k int) (ans int) {
134134
}
135135
```
136136

137+
### **TypeScript**
138+
139+
```ts
140+
function numberOfSubarrays(nums: number[], k: number): number {
141+
const n = nums.length;
142+
const cnt = new Array(n + 1).fill(0);
143+
cnt[0] = 1;
144+
let ans = 0;
145+
let t = 0;
146+
for (const v of nums) {
147+
t += v & 1;
148+
if (t - k >= 0) {
149+
ans += cnt[t - k];
150+
}
151+
cnt[t] += 1;
152+
}
153+
return ans;
154+
}
155+
```
156+
137157
### **...**
138158

139159
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function numberOfSubarrays(nums: number[], k: number): number {
2+
const n = nums.length;
3+
const cnt = new Array(n + 1).fill(0);
4+
cnt[0] = 1;
5+
let ans = 0;
6+
let t = 0;
7+
for (const v of nums) {
8+
t += v & 1;
9+
if (t - k >= 0) {
10+
ans += cnt[t - k];
11+
}
12+
cnt[t] += 1;
13+
}
14+
return ans;
15+
}

0 commit comments

Comments
 (0)