We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 138d828 commit d6f770cCopy full SHA for d6f770c
README.md
@@ -10,6 +10,8 @@ leetcode 测试
10
11
##### 包含的内容如下
12
13
+https://leetcode.cn/problems/reverse-prefix-of-word/
14
+
15
https://leetcode.cn/problems/counting-words-with-a-given-prefix/
16
17
https://leetcode.cn/problems/maximum-product-difference-between-two-pairs/
reverse-prefix-of-word/index.ts
@@ -0,0 +1,11 @@
1
+function reversePrefix(word: string, ch: string): string {
2
+ const index = Array.prototype.findIndex.call(word, (c) => c === ch);
3
4
+ if (index < 0) return word;
5
+ return (
6
+ Array.from(word.slice(0, index + 1))
7
+ .reverse()
8
+ .join("") + word.slice(index + 1)
9
+ );
+}
+export default reversePrefix;
0 commit comments