58. 最后一个单词的长度 leetcode
2018-11-02 本文已影响1人
出来遛狗了
![](https://img.haomeiwen.com/i1350306/c20c6a99119612ed.png)
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;
}
}