标签:style sequence leetcode ret tput where turn etc public
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.
For example,
Input: "Hello, my name is John"
Output: 5
public int countSegments(String s) { String trimmed = s.trim(); if (trimmed.length() == 0) return 0; else return trimmed.split("\\s+").length; }
每天一道LeetCode--434. Number of Segments in a String
标签:style sequence leetcode ret tput where turn etc public
原文地址:http://www.cnblogs.com/xiaoduc-org/p/6135563.html