File tree 3 files changed +58
-0
lines changed
solution/0200-0299/0290.Word Pattern
3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,27 @@ class Solution {
92
92
}
93
93
```
94
94
95
+ ### ** TypeScript**
96
+
97
+ ``` ts
98
+ function wordPattern(pattern : string , s : string ): boolean {
99
+ let n = pattern .length ;
100
+ let values = s .split (' ' );
101
+ if (n != values .length ) return false ;
102
+ let table = new Array (128 );
103
+ for (let i = 0 ; i < n ; i ++ ) {
104
+ let k = pattern .charCodeAt (i ), v = values [i ];
105
+ if (! table [k ]) {
106
+ if (table .includes (v )) return false ;
107
+ table [k ] = v ;
108
+ } else {
109
+ if (table [k ] != v ) return false ;
110
+ }
111
+ }
112
+ return true ;
113
+ };
114
+ ```
115
+
95
116
### ** ...**
96
117
97
118
```
Original file line number Diff line number Diff line change @@ -102,6 +102,27 @@ class Solution {
102
102
}
103
103
```
104
104
105
+ ### ** TypeScript**
106
+
107
+ ``` ts
108
+ function wordPattern(pattern : string , s : string ): boolean {
109
+ let n = pattern .length ;
110
+ let values = s .split (' ' );
111
+ if (n != values .length ) return false ;
112
+ let table = new Array (128 );
113
+ for (let i = 0 ; i < n ; i ++ ) {
114
+ let k = pattern .charCodeAt (i ), v = values [i ];
115
+ if (! table [k ]) {
116
+ if (table .includes (v )) return false ;
117
+ table [k ] = v ;
118
+ } else {
119
+ if (table [k ] != v ) return false ;
120
+ }
121
+ }
122
+ return true ;
123
+ };
124
+ ```
125
+
105
126
### ** ...**
106
127
107
128
```
Original file line number Diff line number Diff line change
1
+ function wordPattern ( pattern : string , s : string ) : boolean {
2
+ let n = pattern . length ;
3
+ let values = s . split ( ' ' ) ;
4
+ if ( n != values . length ) return false ;
5
+ let table = new Array ( 128 ) ;
6
+ for ( let i = 0 ; i < n ; i ++ ) {
7
+ let k = pattern . charCodeAt ( i ) , v = values [ i ] ;
8
+ if ( ! table [ k ] ) {
9
+ if ( table . includes ( v ) ) return false ;
10
+ table [ k ] = v ;
11
+ } else {
12
+ if ( table [ k ] != v ) return false ;
13
+ }
14
+ }
15
+ return true ;
16
+ } ;
You can’t perform that action at this time.
0 commit comments