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

Commita1ea4d7

Browse files
authored
Improved task 290
1 parent5a466ca commita1ea4d7

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

‎src/main/ts/g0201_0300/s0290_word_pattern/solution.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22
// #2025_04_12_Time_0_ms_(100.00%)_Space_55.01_MB_(70.10%)
33

44
functionwordPattern(pattern:string,s:string):boolean{
5-
constmap=newMap<string,string>();
6-
constwords=s.split(" ");
5+
constmap=newMap<string,string>()
6+
constwords=s.split(' ')
77
if(words.length!==pattern.length){
8-
returnfalse;
8+
returnfalse
99
}
1010
for(leti=0;i<pattern.length;i++){
11-
constchar=pattern[i];
12-
constword=words[i];
11+
constchar=pattern[i]
12+
constword=words[i]
1313
if(!map.has(char)){
1414
if([...map.values()].includes(word)){
15-
returnfalse;
15+
returnfalse
1616
}
17-
map.set(char,word);
17+
map.set(char,word)
1818
}else{
1919
if(map.get(char)!==word){
20-
returnfalse;
20+
returnfalse
2121
}
2222
}
2323
}
24-
returntrue;
24+
returntrue
2525
}
2626

2727
export{wordPattern}

‎src/test/ts/g0201_0300/s0290_word_pattern/solution.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@ test('wordPattern2', () => {
1313
test('wordPattern3',()=>{
1414
expect(wordPattern('aaaa','dog cat cat dog')).toEqual(false)
1515
})
16+
17+
test('wordPattern4',()=>{
18+
expect(wordPattern('a','dog cat')).toEqual(false)
19+
})
20+
21+
test('wordPattern5',()=>{
22+
expect(wordPattern('a','dog')).toEqual(true)
23+
})
24+
25+
test('wordPattern6',()=>{
26+
expect(wordPattern('ab','dog dog')).toEqual(false)
27+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp