Reverse Words in a String - LeetCode #151 - Python, JavaScript, Java, C++

preview_player
Показать описание
Reverse Words in a String with Python, JavaScript, Java and C++, LeetCode #151!

Check out my latest video where I break down the Reverse Words in a String problem from LeetCode 151! In this video, I'll show you step-by-step how to reverse the words in a string while removing extra spaces. The Reverse Words in a String problem is a common interview question that tests your understanding of string manipulation. I’ll also cover how to optimize the solution and explain why this approach works best for LeetCode 151. If you’re preparing for coding interviews, make sure to watch and get familiar with Reverse Words in a String to ace your next interview!

------------------------------------------------------------------------------------------------------
⭐️ Please subscribe to my channel from here.

⭐️ Please upvote my post from here.
------------------------------------------------------------------------------------------------------

■ Timeline
0:05 Explain basic idea for solution 1
2:25 Coding for solution 1
3:59 Time Complexity and Space Complexity for solution 1
4:29 Explain basic idea for solution 2
5:55 Coding for solution 2
7:10 Time Complexity and Space Complexity for solution 2
7:18 Bonus Code
8:12 Time Complexity and Space Complexity for Bonus Code

■ Blind 75 LeetCode questions

■ Twitter

■ Problem Link

■ Codes in the video
- Python, JavaScript, Java and C++ are available from here.

■ Other Playlists

#leetcode #python #interview
Рекомендации по теме
Комментарии
Автор

Thanks for the video! Expanding on your last solution, you could slice the string with a -1 step in the same line to obtain the same result like this:

class Solution:
def reverseWords(self, s: str) -> str:
return ' '.join(s.split()[::-1])

However, i believe your use of reversed is definitely cleaner to read. Also, thank you for showing multiple solutions in the same video. I enjoyed that!

AppleDeuceTTV
join shbcf.ru