File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 86
86
| 276 | 🔒 [ Paint Fence] ( https://leetcode.com/problems/paint-fence ) | Easy | |
87
87
| 278 | [ First Bad Version] ( https://leetcode.com/problems/first-bad-version ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/FirstBadVersion.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/first_bad_version.py ) |
88
88
| 283 | [ Move Zeroes] ( https://leetcode.com/problems/move-zeroes ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/MoveZeros.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/move_zeroes.py ) |
89
- | 290 | [ Word Pattern] ( https://leetcode.com/problems/word-pattern ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/WordPattern.java ) |
89
+ | 290 | [ Word Pattern] ( https://leetcode.com/problems/word-pattern ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/WordPattern.java ) [ ![ Python ] ( https://img.icons8.com/color/35/000000/python.png )] ( python/word_pattern.py ) |
90
90
| 292 | [ Nim Game] ( https://leetcode.com/problems/nim-game ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NimGame.java ) |
91
91
| 293 | [ Flip Game] ( https://leetcode.com/problems/flip-game ) | Easy | |
92
92
| 299 | [ Bulls and Cows] ( https://leetcode.com/problems/bulls-and-cows ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BullsAndCows.java ) |
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def wordPattern (self , pattern : str , s : str ) -> bool :
3
+ words = s .split ()
4
+ if len (words ) != len (pattern ):
5
+ return False
6
+ mapping = {}
7
+ used_words = set ()
8
+ for character , word in zip (pattern , words ):
9
+ if character in mapping :
10
+ if mapping [character ] != word :
11
+ return False
12
+ elif word in used_words :
13
+ return False
14
+ else :
15
+ mapping [character ] = word
16
+ used_words .add (word )
17
+ return True
18
+
19
+
20
+ print (Solution ().wordPattern ('abba' , 'dog dog dog dog' ))
You can’t perform that action at this time.
0 commit comments