Skip to content

Commit 54c8ad0

Browse files
committed
Create 1392.最长快乐前缀.js
1 parent b94705e commit 54c8ad0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

1392.最长快乐前缀.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
暴力搜索就可以, 数据太弱了...
3+
*/
4+
5+
/**
6+
* @param {string} s
7+
* @return {string}
8+
*/
9+
var longestPrefix = function(s) {
10+
if (s.length <= 1) {
11+
return '';
12+
}
13+
for (let i = s.length - 1; i > 0; i--) {
14+
if (s.slice(0, i) === s.slice(s.length - i)) {
15+
return s.slice(0, i);
16+
}
17+
}
18+
return '';
19+
};

0 commit comments

Comments
 (0)