public int lengthOfLastWord(String s) {
            int result = 0;
            int cur = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == ' ') {
                    if (cur != 0)
                        result = cur;
                    cur = 0;
                } else {
                    cur++;
                }
            }
            if (cur == 0)
                return result;
            else
                return cur;
        }