Skip to content

Commit e31c6a6

Browse files
authored
Update Length of last word.java
1 parent 1a28571 commit e31c6a6

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Easy/Length of last word.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
class Solution {
22
public int lengthOfLastWord(String s) {
3-
int count = 0;
43
int idx = s.length() - 1;
54
while (idx >= 0 && s.charAt(idx) == ' ') {
65
idx--;
76
}
7+
int currIdx = idx;
88
while (idx >= 0 && s.charAt(idx) != ' ') {
99
idx--;
10-
count++;
1110
}
12-
return count;
11+
return currIdx - idx;
1312
}
1413
}

0 commit comments

Comments
 (0)