๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/Algorithm

[๋ฐฑ์ค€][Node.js] 10818๋ฒˆ : ์ตœ์†Œ, ์ตœ๋Œ€

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2022. 3. 4.

 

 

Algorithm

-  ์ตœ์†Œ, ์ตœ๋Œ€ -

 


 

๋ฌธ์ œ

N๊ฐœ์˜ ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, ์ตœ์†Ÿ๊ฐ’๊ณผ ์ตœ๋Œ“๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

๋ฌธ์ œ ํ’€๊ธฐ

let fs = require("fs");
let input = fs.readFileSync("/dev/stdin").toString().split('\n');
let arr = input[1].split(' ');
let min = Number(arr[0]);
let max = Number(arr[0]);

for(let i = 0; i < arr.length; i++) {
  if(Number(arr[i]) < min) min = Number(arr[i]);
  if(Number(arr[i]) > max) max = Number(arr[i]);
}

console.log(min, max);

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€