首页 > 其他 > 详细

58. Length of Last Word

时间:2018-03-15 17:40:18      阅读:144      评论:0      收藏:0      [点我收藏+]

原题链接:https://leetcode.com/problems/length-of-last-word/description/
这题目没啥难度,稍微懂点编程均可独立完成:

class Solution {
    public int lengthOfLastWord(String s) {
        int len = 0;
        
        char[] chars = s.toCharArray();
        for (int i = chars.length - 1; i >= 0; i--) {
            if (chars[i] == ‘ ‘) {
                if (len > 0) {
                    return len;
                }
            } else {
                len++;
            }
        }
        
        return len;
    }
}

58. Length of Last Word

原文:https://www.cnblogs.com/optor/p/8574626.html

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