Загрузка...

58. Length of Last Word | LeetCode Easy | C++ Solution

Problem Name: 58. Length of Last Word

In this video, I solved LeetCode 58 “Length of Last Word” using C++ with an easy step-by-step explanation.

📌 Problem Statement:
Given a string s, return the length of the last word in the string.

📌 Approach Used:
- Start from the end of the string
- Ignore spaces at the end
- Count characters of the last word
- Stop when a space comes after counting starts
- Return the count

📌 Example:
Input:
s = "Hello World"

Output:
5

Explanation:
The last word is "World", and its length is 5.

📌 Concepts Covered:
✅ Strings
✅ Loops
✅ Reverse Traversal
✅ Conditions
✅ Time & Space Complexity

📌 Time Complexity:
O(n)

📌 Space Complexity:
O(1)

📌 Language Used:
C++

🔗 GitHub:
https://github.com/amankumar1508

🔗 LinkedIn:
https://www.linkedin.com/in/aman-kumar-067825379

🔗 Portfolio:
https://aman-kumar-dev-portfolio.vercel.app

🔗 LeetCode Profile:
https://leetcode.com/u/OVzm6rcAP2/

#leetcode
#cplusplus
#cpp
#leetcode58
#string
#dsa
#coding
#programming

Видео 58. Length of Last Word | LeetCode Easy | C++ Solution канала Aman Kumar
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять