LeetCode 290. Word Pattern Solution Explained - Java

  Рет қаралды 15,270

Nick White

Nick White

Күн бұрын

Пікірлер: 15
@NoWarForever
@NoWarForever 4 жыл бұрын
map.containsValue has O(N) time complexity if instead of 1 Map you use 2 Maps you can improve the time complexity while sacrificing the space
@wolfofthelight5690
@wolfofthelight5690 4 жыл бұрын
One thing I had an issue with here was that the pattern length must equal the string length. I passed the leetcode problem before coming here, but it was the last issue I went into. The question is ambiguous. If it is a pattern, there is no reason the string cannot be longer. For example "abba" and "dog cat cat dog dog cat cat dog". In my original solution to the problem, I accounted for this.... the sentence still "fits" the pattern. The problem does not accept this, however, and I removed it and passed the leetcode problem easily. The reason I comment is, if you are asked this in an interview or something, be prepared to ask whether the pattern can recur or if its length is an actual integral part (in which case, it really isn't a pattern so much as simply a one-to-one mapping).
@pushpendrasingh777
@pushpendrasingh777 Жыл бұрын
Tried this same algorithm using the c++ was not able to get it but now it seems easy...
@samandarboymurodov8941
@samandarboymurodov8941 3 жыл бұрын
Thank you. it is clean and easy to understand
@Ben-pb7ct
@Ben-pb7ct 3 жыл бұрын
always one of the best explanation
@bofeng7874
@bofeng7874 4 жыл бұрын
Thank you! Easy to understand!
@sandipchanda6522
@sandipchanda6522 4 жыл бұрын
Nice solution
@cupofjava5480
@cupofjava5480 2 жыл бұрын
better way is using two HashMaps
@1314rom
@1314rom 3 жыл бұрын
thank u ur awesome!
@0anant0
@0anant0 4 жыл бұрын
Elegant!
@ramsharma6425
@ramsharma6425 2 жыл бұрын
doest looks a "easy " problem to me
@sriramsatvikatukuri3341
@sriramsatvikatukuri3341 4 жыл бұрын
class Solution { public boolean wordPattern(String pattern, String str) { String []sa=str.split(" "); if(pattern == null || sa.length!=pattern.length()) return false; int n=pattern.length(); Map m=new HashMap(); Map m1=new HashMap(); for(int i=0;i
@aayushpagare9366
@aayushpagare9366 4 жыл бұрын
It's a request please don't use Java ....use c++ in your videos🙏🙏🙏🙏🙏🙏
@melvinkimathi8924
@melvinkimathi8924 3 жыл бұрын
He dreams in Java bro
@saranshagrawal3448
@saranshagrawal3448 2 жыл бұрын
c++ is noob language and if u have problem with java then go for other source🥴
LeetCode Buddy Strings Solution Explained - Java
9:21
Nick White
Рет қаралды 10 М.
5. Word Pattern 🔥| Strings - Easy | Leetcode 290 | Hashmap
13:36
Ayushi Sharma
Рет қаралды 14 М.
CAN YOU DO THIS ?
00:23
STORROR
Рет қаралды 46 МЛН
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 60 МЛН
HELP!!!
00:46
Natan por Aí
Рет қаралды 32 МЛН
ROSÉ & Bruno Mars - APT. (Official Music Video)
02:54
ROSÉ
Рет қаралды 245 МЛН
LeetCode 697. Degree of an Array (Algorithm Explained)
12:06
Nick White
Рет қаралды 21 М.
I Got Rejected (again)
9:43
Nick White
Рет қаралды 205 М.
Word Pattern | LeetCode 290 | C++, Java, Python
20:04
Knowledge Center
Рет қаралды 10 М.
Self Taught Programmers... Listen Up.
11:21
Nick White
Рет қаралды 1,1 МЛН
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 283 М.
Coding Was Hard Until I Learned THESE 5 Things!
8:02
Nick White
Рет қаралды 32 М.
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,2 МЛН
LeetCode 67. Add Binary Solution Explained - Java
10:24
Nick White
Рет қаралды 47 М.
LeetCode 238. Product of Array Except Self (Solution Explained)
14:49
Yanlışlıkla Telefonum Parçalandı!😱
0:19
Safak Novruz
Рет қаралды 514 М.
👍🏻 Samsung Galaxy A56 - ЕГО ЗАХОТЯТ ВСЕ! Xiaomi так не сможет…
12:05
Thebox - о технике и гаджетах
Рет қаралды 40 М.