Skip to content

Commit 7c4259e

Browse files
committed
https://leetcode.cn/problems/check-if-string-is-a-prefix-of-array/
1 parent 9fa364a commit 7c4259e

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ https://leetcode.cn/problems/longest-palindromic-substring
584584

585585
https://leetcode.cn/problems/remove-nth-node-from-end-of-list
586586

587+
https://leetcode.cn/problems/check-if-string-is-a-prefix-of-array/
588+
587589
#### 安装教程
588590

589591
1. 安装`deno`
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default function isPrefixString(s: string, words: string[]): boolean {
2+
for (const word of words) {
3+
if (s.startsWith(word)) {
4+
s = s.slice(word.length);
5+
if (s.length === 0) return true;
6+
} else {
7+
return false;
8+
}
9+
}
10+
return false;
11+
}

longest-palindromic-substring/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function longestPalindrome(s: string): string {
77
const str1 = expand(s, i, i);
88
const str2 = expand(s, i, i + 1);
99
ans = [str1, str2].reduce((p, v) => (p.length > v.length ? p : v), ans);
10-
if(ans===s)return s
10+
if (ans === s) return s;
1111
i = i + 1;
1212
}
1313
return ans;

0 commit comments

Comments
 (0)