문제 🔽
https://school.programmers.co.kr/learn/courses/30/lessons/140108
다른사람 풀이 🔽
function solution(s) {
let answer = 0;
let current;
let count = 0;
for(let i = 0; i < s.length; i++) {
if(count === 0) {
answer++;
current = s[i]
count = 1
} else {
if(current !== s[i]) count--;
else count++;
}
}
return answer;
}
내풀이🔽
1. 성공 ⭕
function solution(s){
var answer = 0;
let arr=[0,0]
let refIndex = 0;
for(let i=0; i<s.length; i++){
if(s[refIndex]===s[i]){
++arr[0]
}else{
++arr[1]
}
if(arr[0]===arr[1]){
++answer;
refIndex=i+1;
}
if(i===s.length-1&&arr[0]!==arr[1]){
++answer
}
}
return answer;
}
느낀점🔽
lv1을 오랜만에 풀어보았다 생각보다 오래 걸렸지만
큰 어려움 없이 풀어서 기분이 좋았다..!