Skip to content

Commit 53b3792

Browse files
authored
Merge pull request #2299 from gourgopal/patch-9
Update 0058-length-of-last-word.cs
2 parents e4e697f + 00a3b8e commit 53b3792

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: csharp/0058-length-of-last-word.cs

+14
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,17 @@ public int LengthOfLastWord(string s) {
66
}
77
}
88

9+
public class NeetCodeSolution {
10+
public int LengthOfLastWord(string s) {
11+
var result = 0;
12+
var i = s.Length - 1;
13+
while (s[i] == ' ') --i;
14+
for (; i >= 0; --i) {
15+
if (s[i] == ' ') {
16+
return result;
17+
}
18+
++result;
19+
}
20+
return result;
21+
}
22+
}

0 commit comments

Comments
 (0)