We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a9a2ef1 commit c1fbc98Copy full SHA for c1fbc98
scripts/algorithms/N/Number of Segments in a String/Number of Segments in a String.java
@@ -1,8 +1,9 @@
1
+// Runtime: 0 ms (Top 100.00%) | Memory: 41.9 MB (Top 35.26%)
2
class Solution {
3
public int countSegments(String s) {
4
int length = 0;
5
boolean flag = false;
-
6
+
7
for(Character c : s.toCharArray()) {
8
if(c == ' ' && flag) {
9
length++;
@@ -11,7 +12,7 @@ public int countSegments(String s) {
11
12
flag = true;
13
}
14
15
16
return flag ? length + 1 : length;
17
-}
18
+}
0 commit comments