第76天。
快考试,可能要水一个月的easy
题了。
今天的题目是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.
Note: A word is defined as a character sequence consists of non-space characters only.
Example:
Input: “Hello World” Output: 5
一看完题目,我就想到了python
的split
:
然后是用c++
用find
去解的:
然后是从后面向前扫描的方法:
然后是dicuss
中的解法,和上面的从后向前扫描的方法类似,只不过它第二个循环里面顺带计算了length
: