class Solution {
func lengthOfLastWord(_ s: String) -> Int {
if s.count == 0{
return 0;
}
var lenth = 0;
var start = false;
for (_,value) in s.enumerated().reversed(){
if value == " "{
if start{
return lenth;
}
}else {
lenth += 1
start = true;
}
}
return lenth;
}
}
网友评论