Skip to content

Commit a4d5520

Browse files
committed
feat: add typescript solution to lc problem: No.2278
No.2278.Percentage of Letter in String
1 parent 1b61d83 commit a4d5520

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

solution/2200-2299/2278.Percentage of Letter in String/README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,14 @@ func percentageLetter(s string, letter byte) int {
102102
### **TypeScript**
103103

104104
```ts
105-
105+
function percentageLetter(s: string, letter: string): number {
106+
let count = 0;
107+
let total = s.length;
108+
for (let i of s) {
109+
if (i === letter) count++;
110+
}
111+
return Math.floor(count / total * 100);
112+
};
106113
```
107114

108115
### **...**

solution/2200-2299/2278.Percentage of Letter in String/README_EN.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@ func percentageLetter(s string, letter byte) int {
9292
### **TypeScript**
9393

9494
```ts
95-
95+
function percentageLetter(s: string, letter: string): number {
96+
let count = 0;
97+
let total = s.length;
98+
for (let i of s) {
99+
if (i === letter) count++;
100+
}
101+
return Math.floor(count / total * 100);
102+
};
96103
```
97104

98105
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function percentageLetter(s: string, letter: string): number {
2+
let count = 0;
3+
let total = s.length;
4+
for (let i of s) {
5+
if (i === letter) count++;
6+
}
7+
return Math.floor(count / total * 100);
8+
};

0 commit comments

Comments
 (0)