Skip to content

Commit

Permalink
Created: 58-Length-of-Last-Word.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
loczek committed Nov 1, 2022
1 parent aa1fbd6 commit a320856
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions typescript/58-Length-of-Last-Word.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function lengthOfLastWord(s: string): number {
let res = 0;
for (let i = s.length - 1; i > -1; i--) {
if (s[i] === ' ' && res === 0) continue;
if (s[i] === ' ') break;
res += 1;
}
return res;
}

0 comments on commit a320856

Please sign in to comment.