Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitec5c781

Browse files
committed
Set up Deno testing
1 parent24ae46c commitec5c781

File tree

4 files changed

+71
-15
lines changed

4 files changed

+71
-15
lines changed

‎Medium/LongestPalindromicSubstring.ts‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
/*
2-
* Problem: Longest Palindromic Substring
2+
* Problem:5.Longest Palindromic Substring
33
* Acceptance Rate: 31.0%
44
* URL: https://leetcode.com/problems/longest-palindromic-substring/
55
*
66
* Runtime: 96 ms, faster than 96.82% of TypeScript online submissions for Longest Palindromic Substring.
77
* Memory Usage: 41.9 MB, less than 65.68% of TypeScript online submissions for Longest Palindromic Substring.
88
*/
99

10-
exportdefaultclassSolution{
10+
exportdefaultfunctionlongestPalindromeIn(s:string):string{
11+
// let result = Solution.findLongestPalindrome(s);
12+
// console.log(s, "->", result);
13+
// return result;
14+
15+
returnSolution.findLongestPalindrome(s);
16+
};
17+
18+
classSolution{
1119

1220
privatestaticstartIndex:number;
1321
privatestaticpalindromeLength:number;
@@ -26,13 +34,13 @@ export default class Solution {
2634
returns.substring(Solution.startIndex,Solution.startIndex+Solution.palindromeLength);
2735
};
2836

29-
privatestaticextendPalindromeEvenLength(s:string,startingIndex:number){
30-
letleft=startingIndex,right=startingIndex+1;
37+
privatestaticextendPalindromeOddLength(s:string,startingIndex:number){
38+
letleft=startingIndex,right=startingIndex;
3139
Solution.extendPalindrome(s,left,right);
3240
}
3341

34-
privatestaticextendPalindromeOddLength(s:string,startingIndex:number){
35-
letleft=startingIndex,right=startingIndex;
42+
privatestaticextendPalindromeEvenLength(s:string,startingIndex:number){
43+
letleft=startingIndex,right=startingIndex+1;
3644
Solution.extendPalindrome(s,left,right);
3745
}
3846

@@ -65,14 +73,6 @@ export default class Solution {
6573
}
6674
}
6775

68-
functionlongestPalindromeIn(s:string):string{
69-
letresult=Solution.findLongestPalindrome(s);
70-
71-
console.log(s,"->",result);
72-
73-
returnresult;
74-
};
75-
7676
//---------------------------------------------------------------------
7777
// ---------- MAIN PROGRAM ----------
7878
//---------------------------------------------------------------------
@@ -82,7 +82,7 @@ if(import.meta.main) {
8282
longestPalindromeIn("cbbd");
8383
longestPalindromeIn("weloveracecars");
8484

85-
// RUN: deno runMedium/LongestPalindromicSubstring.ts
85+
// RUN: deno runmedium/LongestPalindromicSubstring.ts
8686
}
8787

8888
// --------------------------- Terminal Output: ---------------------------
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import{assertEquals,assertNotEquals}from'../../test_deps.ts';
2+
3+
importlongestPalindromeInfrom"../LongestPalindromicSubstring.ts";
4+
5+
6+
// RUN: deno test medium/test/LongestPalindromicSubstring.test.ts
7+
8+
//---------------------------------------------------------------------
9+
// ---------- UNIT TESTS ----------
10+
//---------------------------------------------------------------------
11+
12+
Deno.test({
13+
name:"babad -> bab",
14+
fn(){
15+
assertEquals(longestPalindromeIn("babad"),"bab");
16+
}
17+
});
18+
19+
20+
Deno.test({
21+
name:"babad -> !aba",
22+
fn(){
23+
assertNotEquals(longestPalindromeIn("babad"),"aba");
24+
}
25+
});
26+
27+
Deno.test({
28+
name:"cbbd -> bb",
29+
fn(){
30+
assertEquals(longestPalindromeIn("cbbd"),"bb");
31+
}
32+
});
33+
34+
Deno.test({
35+
name:"weloveracecars -> racecar",
36+
fn(){
37+
assertEquals(longestPalindromeIn("weloveracecars"),"racecar");
38+
}
39+
});

‎README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#Leetcode Solutions in TypeScript
2+
3+
##Environment
4+
- <spantitle="July 2021">Deno 1.12.0</span>
5+
- V8 9.2.230.14
6+
- TypeScript 4.3.2
7+
8+
##Problems Completed
9+
10+
###Medium
11+
- <spantitle="Acceptance Rate: 31.0%">5. Longest Palindromic Substring</span>

‎test_deps.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// ----------------------- Testing Library -----------------------
2+
export{
3+
assert,
4+
assertEquals,
5+
assertNotEquals,
6+
}from"https://deno.land/std@0.101.0/testing/asserts.ts";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp