Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1252 from tharunkanna14/patch-4
Browse files Browse the repository at this point in the history
Create 0058_length_of_last_word.java
  • Loading branch information
Ahmad-A0 authored Nov 2, 2022
2 parents 9999adc + f6bf377 commit a35232f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions java/58-Length-Of-Last-Word.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public int lengthOfLastWord(String s) {
int i = s.length() - 1, length = 0;
while (s.charAt(i) == ' ') {
i -= 1;
}
while (i >= 0 && s.charAt(i) != ' ') {
length += 1;
i -= 1;
}
return length;
}
}

0 comments on commit a35232f

Please sign in to comment.