We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8e089e3 commit 63e9fe8Copy full SHA for 63e9fe8
CntSegments.java
@@ -0,0 +1,31 @@
1
+public class CntSegments {
2
+ public int countSegments(String s) {
3
+ return s.length() == 0? 0: s.split(" ").length;
4
+ }
5
+}
6
+
7
+/* best solution
8
+class Solution {
9
10
+ int res=0;
11
+ int n = s.length();
12
+ int i=0;
13
+ boolean flag;
14
+ while(i<n){
15
+ flag=false;
16
+ while(i<n && s.charAt(i)!=' '){
17
+ i++;
18
+ flag=true;
19
20
+ if(flag)
21
+ res++;
22
+ while(i<n && s.charAt(i)==' ')
23
+ {
24
25
26
27
28
+ return res;
29
30
31
+ */
0 commit comments