본문 바로가기

일반 학습/코딩 테스트59

[프로그래머스] 튜플 function solution(s) { s = s.split("},{"); let newArr = s.map((el) => { if (el[0] === "{" || el[1] === "{") { return el.slice(2); } if (el[el.length - 1] === "}" || el[el.length - 2] === "}") { return el.slice(0, -2); } else return el; }); let convert = []; for (let i = 0; i < newArr.length; i++) { let pushArr = []; for (let j = 0; j < newArr[i].split(",").length; j++) { pushArr.push(parseInt(ne.. 2022. 3. 7.
[프로그래머스] 수식 최대화 function solution(expression) { const prior = [ ["-", "*", "+"], ["-", "+", "*"], ["+", "*", "-"], ["+", "-", "*"], ["*", "+", "-"], ["*", "-", "+"], ]; function reset(expression) { let newArr = []; let vertical = 0; for (let i = 0; i < expression.length; i++) { if (expression[i] === "-" || expression[i] === "*" || expression[i] === "+") { newArr.push(expression.slice(vertical, i)); newArr.push(.. 2022. 3. 7.
[프로그래머스] 거리두기 확인하기 function solution(places) { let result = []; for (let i = 0; i < places.length; i++) { if (getstart(places[i])) { result.push(1); } else { result.push(0); } } return result; } function getstart(p) { let person = []; for (let i = 0; i < p.length; i++) { for (let j = 0; j < p[i].length; j++) { if (p[i][j] === "P") { person.push([i, j]); } } } let calcperson = []; for (let i = 0; i < person.length .. 2022. 3. 7.
[프로그래머스] 뉴스 클러스터링 처음 작성한 코드 function solution(p1, p2) { let middelArr = []; p1 = p1.toUpperCase(); p2 = p2.toUpperCase(); const arr1 = new Array(); const arr2 = new Array(); for (let i = 0; i = "A" && str[0] = "A" && str[1] = "A" && str[0] = "A" && str[1] arr2.includes(it)).length, arr2.filter((it) => arr1.includes(it)).length); arr1.sort(); arr2.so.. 2022. 3. 6.
[프로그래머스] 괄호 변환 function solution(p) { let left = 0; let right = 0; let answer = ""; if (p === "") return ""; for (let i = 0; i < p.length; i++) { if (p[i] === "(") left++; else if (p[i] === ")") right++; if (left === right) { if (check(p.slice(0, i + 1))) { answer = p.slice(0, i + 1) + solution(p.slice(i + 1)); return answer; } else { answer = "(" + solution(p.slice(i + 1)) + ")"; for (let j = 1; j < i; j++) {.. 2022. 3. 5.
[프로그래머스] 문자열 압축 function solution(s) { let answer = s.length; for (let i = 1; i 2022. 3. 4.