Length of Last Word - Leetcode - Javascript Solution

Опубликовано: 30 Декабрь 2020
на канале: The Coding Odyssey
1,008
26

In this video we are solving another coding challenge from leetcode called Length of Last Word using javascript:

Given a string s consists of some words separated by spaces, return the length of the last word in the string. If the last word does not exist, return 0.

A word is a maximal substring consisting of non-space characters only.

Timestamps:

00:00 Length of Last Word
00:59 How to split string into array of words
02:09 Trimming the string
03:03 Remove and store last element from array of words
03:59 Using the OR operator to take care of edge case
04:07 Returning length of string
04:41 Refactoring Code
05:25 Using the ternary operator to decide between 2 cases

Here's the link to the coding challenge:

Leetcode - Length of Last Word : https://leetcode.com/problems/length-...

#lengthoflastword #58.lengthoflastword #lengthoflastwordjavascript #leetcodejavascriptsolutions #leetcodejavascript