백준-Node.js-1085

송철진·2023년 2월 7일
0

백준-Node.js

목록 보기
8/69

풀이

const fs = require('fs')
const [x, y, w, h] = fs.readFileSync('/dev/stdin').toString().trim().split(' ')

const solution = (x,y,w,h) => {
  return Math.min(x, y, w-x, h-y)
}

console.log( solution(x,y,w,h) )

점 (x, y)를 기준으로 직사각형 경계까지의 거리는
x, 우 w-x, 상 h-y, 하 y 이므로
Math.min() 메서드를 사용하여 최소값을 반환하도록 한다

profile
검색하고 기록하며 학습하는 백엔드 개발자

0개의 댓글