c语言sscanf函数的用法是什么
237
2022-09-17
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:
Input: "Hello, my name is John"Output: 5
class Solution { public int countSegments(String s) { int segmentCount = 0; for (int i = 0; i < s.length(); i++) { if ((i == 0 || s.charAt(i-1) == ' ') && s.charAt(i) != ' ') { segmentCount++; } } return
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~