REVERSE WORDS IN A STRING | LEETCODE 151 | PYTHON SOLUTION

  Рет қаралды 8,315

Cracking FAANG

Cracking FAANG

Күн бұрын

Пікірлер: 13
@dnm9931
@dnm9931 Ай бұрын
Guys it looks like ‘i-1’ isn’t needed, ,y solution passes all test cases when I submit it without that line! Thanks so much,Cush cracking faang for the vid! You probably see me commenting on all your vids now!
@kingfriizy5707
@kingfriizy5707 10 ай бұрын
its a medium because the follow up is solve in constant memory
@barybary42
@barybary42 5 ай бұрын
which is not that straightforward
@Ammar23217
@Ammar23217 Жыл бұрын
very good solution
@crackfaang
@crackfaang Жыл бұрын
Thanks mate, glad you found it helpful
@arkachaudhuri7339
@arkachaudhuri7339 6 ай бұрын
Hey, Can someone explain the purpose for the i -= 1 after parsing the string builder? Shouldn't it anyway iterate forth to the next if it encounters a whitespace?
@elias043011
@elias043011 6 ай бұрын
He's moving it back WITHIN the if statement because after exiting the if conditional block, he adds to "i" again.. you could get around this by checking ahead in the nested while statement while i + 1 < len(s) and s[i + 1] != " ":
@wentaogao1118
@wentaogao1118 2 жыл бұрын
Thanks., very nice solution
@crackfaang
@crackfaang 2 жыл бұрын
Thanks for the kind words! Make sure to subscribe so you don’t miss future videos
@pshi1989
@pshi1989 2 жыл бұрын
thank you 😊
@MohitJain-dt4nb
@MohitJain-dt4nb 5 ай бұрын
why can't we simply do this-: class Solution: def reverseWords(self, s: str) -> str: words = s.split() return ' '.join(reversed(words))
@GiaBìnhVũ-w4s
@GiaBìnhVũ-w4s 3 ай бұрын
yoooo that is much better, ty !!
@luuc
@luuc Ай бұрын
That's definitely one way to solve it. Though, the idea behind the question is to practice a specific competitive programming pattern (two-pointer). Can you solve it without any memory usage?
BASIC CALCULATOR | LEETCODE # 224 | PYTHON SOLUTION
21:06
Cracking FAANG
Рет қаралды 25 М.
СКОЛЬКО ПАЛЬЦЕВ ТУТ?
00:16
Masomka
Рет қаралды 3,4 МЛН
How I Would Learn Python FAST in 2024 (if I could start over)
12:19
Thu Vu data analytics
Рет қаралды 552 М.
5 Wacky Python Features
15:37
Indently
Рет қаралды 18 М.
New divisibility rule! (30,000 of them)
26:51
Stand-up Maths
Рет қаралды 289 М.
Reverse String - 3 Ways - Leetcode 344 - Python
9:03
NeetCode
Рет қаралды 59 М.
5 Good Python Habits
17:35
Indently
Рет қаралды 623 М.
Reverse Words in a String | LeetCode 151 | C++, Java, Python
13:58
Knowledge Center
Рет қаралды 191 М.
Reverse Words in a String III - Leetcode 557 - Python
10:18
NeetCodeIO
Рет қаралды 18 М.
String Compression
11:48
Kevin Naughton Jr.
Рет қаралды 95 М.
Leetcode 151 Reverse Words in a String
25:27
Ren Zhang
Рет қаралды 1,2 М.
СКОЛЬКО ПАЛЬЦЕВ ТУТ?
00:16
Masomka
Рет қаралды 3,4 МЛН