Skip to content

Commit 63e9fe8

Browse files
committed
세그먼트 카운트
1 parent 8e089e3 commit 63e9fe8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

CntSegments.java

+31
Original file line numberDiff line numberDiff line change
@@ -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+
public int countSegments(String s) {
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+
i++;
25+
}
26+
27+
}
28+
return res;
29+
}
30+
}
31+
*/

0 commit comments

Comments
 (0)