Skip to content

Commit 478dc6b

Browse files
committed
feat: add typescript solution to lc problem: No.2185
No.2185.Counting Words With a Given Prefix
1 parent 0d7a902 commit 478dc6b

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

solution/2100-2199/2185.Counting Words With a Given Prefix/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@
6363
### **TypeScript**
6464

6565
```ts
66+
function prefixCount(words: string[], pref: string): number {
67+
const n = pref.length;
68+
let ans = 0;
69+
for (let str of words) {
70+
if (str.substring(0, n) == pref) {
71+
ans++;
72+
}
73+
}
74+
return ans;
75+
};
6676
```
6777

6878
### **...**

solution/2100-2199/2185.Counting Words With a Given Prefix/README_EN.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@
5555
### **TypeScript**
5656

5757
```ts
58+
function prefixCount(words: string[], pref: string): number {
59+
const n = pref.length;
60+
let ans = 0;
61+
for (let str of words) {
62+
if (str.substring(0, n) == pref) {
63+
ans++;
64+
}
65+
}
66+
return ans;
67+
};
5868
```
5969

6070
### **...**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function prefixCount(words: string[], pref: string): number {
2+
const n = pref.length;
3+
let ans = 0;
4+
for (let str of words) {
5+
if (str.substring(0, n) == pref) {
6+
ans++;
7+
}
8+
}
9+
return ans;
10+
};

0 commit comments

Comments
 (0)