LeetCode 434. Number of Segments in a String
题目描述:
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.
Please note that the string does not contain any non-printable characters.
Example:
1
2 Input: "Hello, my name is John"
Output: 5
比较简单,注意处理连续的空格和结尾。还有有符号数与无符号数的隐式转换问题。
1 | class Solution { |