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.
2 parents f1a8f0a + 9b37760 commit 8c6c333Copy full SHA for 8c6c333
Week2/공통/문자열나누기/jiyoon.java
@@ -0,0 +1,30 @@
1
+package Week2.공통.문자열나누기;
2
+
3
+public class jiyoon {
4
+ class Solution {
5
+ public int solution(String s) {
6
+ int answer = 0;
7
+ char x = '0';
8
+ int countX = 0; // x 등장 수
9
+ int countO = 0; // x와 다른 문자 등장 수
10
11
+ for (int i = 0; i < s.length(); i++) {
12
+ if (x == '0') x = s.charAt(i);
13
14
+ if (s.charAt(i) == x) { // x와 동일한 문자가 나왔다면,
15
+ countX++;
16
+ } else if (s.charAt(i) != x) { // x와 다른 문자가 나왔다면,
17
+ countO++;
18
+ }
19
20
+ if (countX == countO) {
21
+ answer++; // 문자열 분할 개수 추가
22
+ x = '0'; // 문자열 초기화
23
24
25
26
+ if ((countX - countO) != 0) answer++; // 더 이상 읽을 문자열이 없다면 문자열 분할 개수 추가
27
+ return answer;
28
29
30
+}
0 commit comments