1.タイトルサイト
https://leetcode.com/problems/number-of-segments-in-a-string/
2.タイトル説明
効果3.被験者
どのように多くの言葉与えられた文字列を返します。単語はスペースで区切られています。
4.問題解決のアイデア
ログインの問題
5. ACコード
class Solution {
public int countSegments(String s) {
int count = 0;
for (int i = 0; i < s.length(); ++i)
if (s.charAt(i) != ' ' && (i == 0 || s.charAt(i - 1) == ' '))
++count;
return count;
}
}