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

http://blog.csdn.net/linhuanmars/article/details/21858067

public class Solution {
    public int lengthOfLastWord(String s)
    {
        // Solution A:
        // return lengthOfLastWord_Char(s);
        
        // Solution B:
        return lengthOfLastWord_Cheating(s);
    }

    /////////////////////
    // Solution B: Cheating
    //    
    private int lengthOfLastWord_Cheating(String s)
    {
        if (s == null)
            return 0;
        String strs[] = s.trim().split(" ");
        return strs[strs.length - 1].length();
    }
    
    /////////////////////
    // Solution A: Char
    //
    private int lengthOfLastWord_Char(String s)
    {
        if (s == null)
            return 0;
            
        int count = 0;
        boolean restart = false;
        for (char c : s.toCharArray())
        {
            if (c == ' ')
            {
                restart = true;
            }
            else
            {
                if (restart)
                {
                    count = 1;
                    restart = false;
                }
                else
                {
                    count ++;
                }
            }
        }
        return count;
    }
}