Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 백준 2108 nodejs
- suspense react-query
- 구름톤 챌린지
- 구름톤 챌린지 회고
- 자바스크립트 스코프
- app router emotion
- 리액트쿼리 suspense
- 프로그래머스 문자열 압축
- 사용성 개선
- 백준 1339번 자바스크립트
- js 거리두기 확인하기
- js 스코프
- js
- 백준 1339번 nodejs
- suspense 동작원리
- js 문자열 압축
- 스코프
- 백준 2108 자바스크립트
- 프로그래머스 거리두기 확인하기
- 옵셔널체이닝
- emotion RSC
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- 자바스크립트 문자열 압축
- 구름톤
- emtion app router
- suspense 비동기
- suspense 병목현상
- next13 emotion
- 백준 1339번 js
- 카카오 코테
Archives
- Today
- Total
Lennon FE
[프로그래머스] 거리두기 확인하기 (javascript) 본문
728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/81302?language=javascript
function solution(places) {
let answer = [];
let count = 0;
for(let i = 0; i < places.length; i++){
Loop :
for(let j = 0; j < places[i].length; j++){
if(places[i][j].includes("PO")){
let res = places[i][j].indexOf("PO");
if(j < 4 && (places[i][j+1].indexOf("OP") === res || places[i][j+1].indexOf("XP") === res)){
count++;
}
}
if(places[i][j].includes("PX")){
let res = places[i][j].indexOf("PX");
if(j < 4 && places[i][j+1].indexOf("OP") === res){
count++;
}
}
if(places[i][j].includes("OP")){
let res = places[i][j].indexOf("OP");
if(j < 4 && (places[i][j+1].indexOf("PO") === res || places[i][j+1].indexOf("PX") === res)){
count++;
}
}
if(places[i][j].includes("XP")){
let res = places[i][j].indexOf("XP");
if(j < 4 && places[i][j+1].indexOf("PO") === res){
count++;
}
}
if(places[i][j].includes("PP") || places[i][j].includes("POP")){
count++;
}
for(let k = 0; k < 3; k++){
if(places[i][k][j] === "P" && places[i][k+1][j] === "O" && places[i][k+2][j] === "P"){
count++;
}
}
for(let k = 0; k < 4; k++){
if(places[i][k][j] === "P" && places[i][k+1][j] === "P"){
count++;
}
}
}
if(count === 0){
answer.push(1);
}
else answer.push(0);
count = 0;
}
return answer;
}
단순하게 안 되는 경우들을 모두 탐색해 안 되는 게 한 개라도 있으면 0 아니면 1을 리턴하도록 했다.
##########################################################################
https://parkparkpark.tistory.com/27
코드 개선 업로드
728x90
반응형
'🔥 Algorithm > Programmers' 카테고리의 다른 글
[프로그래머스] 1차 캐시 (javaScript) (0) | 2021.10.07 |
---|---|
[프로그래머스] 프렌즈 4블록 (javascript) (0) | 2021.09.25 |
[프로그래머스] 문자열 압축 (javascript) (0) | 2021.09.25 |
[프로그래머스] 위클리 챌린지 6주차 (javascript 풀이) (0) | 2021.09.25 |
[프로그래머스] 위클리 챌린지 4주 차 (javascript) (0) | 2021.08.25 |
Comments