const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : './data.txt';
const input = fs
.readFileSync(path)
.toString()
.trim()
.split('\n')
.map((x) => parseInt(x));
const count = input.shift();
const solveBubble = (input) => {
for (let i = input.length - 1; i > 0; i--) {
for (let j = 0; j < i; j++) {
if (input[j] > input[j + 1]) {
let temp = input[j + 1];
input[j + 1] = input[j];
input[j] = temp;
}
}
}
return input;
};
// console.log(solveBubble(input));
const solveSelection = (input) => {
for (let i = 0; i < input.length - 1; i++) {
let indexMin = i;
for (let j = i; j < input.length; j++) {
if (input[j] < input[indexMin]) {
indexMin = j;
}
}
let temp = input[i];
input[i] = input[indexMin];
input[indexMin] = temp;
}
return input;
};
// console.log(solveSelection(input));
์ด์
๋ฒ๋ธ์ ๋ ฌ, ์ ํ์ ๋ ฌ ๊ตฌํ ์๋ฃ! ์๊ฐ๋ณต์ก๋๋ O(n^2)๋ก ๊ต์ฅํ ๋๋ฆฐ ์์ด๋ค์ด์ง๋ง!
๊ตฌํํ๋ ๊ฒ์ ์์๋ฅผ ๊ฐ์!
๋ค์์ ์ฝ์ ์ ๋ ฌ์ ๊ตฌํํด๋ณผ ์์ !
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 10989 (0) | 2022.06.17 |
---|---|
[JS] 2751 (0) | 2022.06.14 |
[JS] 2750 (0) | 2022.06.13 |
[JS] 7568 (0) | 2022.06.08 |
[JS] 2231 (0) | 2022.06.07 |