首页 > 其他 > 详细

Leetcode 58 Length of Last Word 难度:0

时间:2015-08-25 18:26:59      阅读:104      评论:0      收藏:0      [点我收藏+]

https://leetcode.com/problems/length-of-last-word/

int lengthOfLastWord(char* s) {
    int ans = 0;
    int fans = 0;
    for(int i = 0;s[i];i++){
        if (s[i] ==‘ ‘){fans = ans;ans = 0;while(s[i + 1] == ‘ ‘){i++;}}
        else ans++;
    }
    return ans?ans:fans;
}

  

 

Leetcode 58 Length of Last Word 难度:0

原文:http://www.cnblogs.com/xuesu/p/4757921.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!