Skip to content

Commit 97af907

Browse files
committed
feat: add typescript solution to lc problem: No.2262
No.2262.Total Appeal of A String
1 parent 180e482 commit 97af907

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

solution/2200-2299/2262.Total Appeal of A String/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,17 @@ func appealSum(s string) int64 {
148148
### **TypeScript**
149149

150150
```ts
151-
151+
function appealSum(s: string): number {
152+
const n = s.length;
153+
let dp = new Array(n + 1).fill(0);
154+
const hashMap = new Map();
155+
for (let i = 0; i < n; i++) {
156+
const c = s.charAt(i);
157+
dp[i + 1] = dp[i] + i + 1 - (hashMap.get(c) || 0);
158+
hashMap.set(c, i + 1);
159+
}
160+
return dp.reduce((a, c) => a + c, 0);
161+
};
152162
```
153163

154164
### **...**

solution/2200-2299/2262.Total Appeal of A String/README_EN.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,17 @@ func appealSum(s string) int64 {
131131
### **TypeScript**
132132

133133
```ts
134-
134+
function appealSum(s: string): number {
135+
const n = s.length;
136+
let dp = new Array(n + 1).fill(0);
137+
const hashMap = new Map();
138+
for (let i = 0; i < n; i++) {
139+
const c = s.charAt(i);
140+
dp[i + 1] = dp[i] + i + 1 - (hashMap.get(c) || 0);
141+
hashMap.set(c, i + 1);
142+
}
143+
return dp.reduce((a, c) => a + c, 0);
144+
};
135145
```
136146

137147
### **...**
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function appealSum(s: string): number {
2+
const n = s.length;
3+
let dp = new Array(n + 1).fill(0);
4+
const hashMap = new Map();
5+
for (let i = 0; i < n; i++) {
6+
const c = s.charAt(i);
7+
dp[i + 1] = dp[i] + i + 1 - (hashMap.get(c) || 0);
8+
hashMap.set(c, i + 1);
9+
}
10+
return dp.reduce((a, c) => a + c, 0);
11+
};

0 commit comments

Comments
 (0)