230706 짝지어 제거하기

Jongleee·2023년 7월 6일
0

TIL

목록 보기
304/576
public int solution(String s) {
	Deque<Character> stack = new ArrayDeque<>();

	for (char ch : s.toCharArray()) {
		if (!stack.isEmpty() && stack.peek() == ch) {
			stack.pop();
		} else {
			stack.push(ch);
		}
	}

	return stack.isEmpty() ? 1 : 0;
}

출처:https://school.programmers.co.kr/learn/courses/30/lessons/12973

0개의 댓글