Length of Last Word | Data Structure and Algorithm notes
Length of Last Word
Source
- leetcode: Length of Last Word | LeetCode OJ
- lintcode: (422) Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Have you met this question in a real interview? Yes Example Given s = "Hello World", return 5. Note A word is defined as a character sequence consists of non-space characters only.
题解
关键点在于确定最后一个字符串之前的空格,此外还需要考虑末尾空格这一特殊情况,故首先除掉右边的空白字符比较好。
Read full article from Length of Last Word | Data Structure and Algorithm notes
No comments:
Post a Comment