HIT해
[JS 백준] 9012.괄호 본문
728x90
const filePath = process.platform === 'linux' ? '/dev/stdin' : 'input.txt';
const input = require("fs")
.readFileSync(filePath)
.toString()
.trim()
.split("\n");
let TC = input.shift();
hey : for(let i = 0; i < TC; i++){
let tmp = input.shift();
tmp = tmp.trim();
let num = tmp.length;
let count = 0;
let flag = true;
for(let j = 0; j < num; j++){
if(tmp[j] === '('){
count++;
}else{
count--;
}
if(count < 0 ){
//console.log("<0")
console.log("NO");
continue hey;
}
}
if(count === 0){
console.log("YES");
}else{
console.log("NO");
}
}
배운점
배열에 저장된 문자열을 사용할 떄 계속 trim() 을 사용해서 받아주어야한다.
자바의 문법처럼 특정 구문을 continue 하는 기능을 지원한다.
고쳐나가야할점
변수명을 잘 해보자
'Vue > JavaScript 알고리즘' 카테고리의 다른 글
[JS 백준] 11866.요세푸스 문제 0 (0) | 2024.01.07 |
---|---|
[JS 백준] 28279.덱 2 (0) | 2024.01.07 |
[JS 백준] 1929.소수 구하기 (0) | 2024.01.06 |
[JS 백준] 1978.소수찾기 (0) | 2024.01.05 |
[JS 백준] 10798.세로읽기 (0) | 2024.01.05 |