-
[λ°±μ€] 24263λ²: μκ³ λ¦¬μ¦ μμ - μκ³ λ¦¬μ¦μ μν μκ° 2 (Node.js)π μκ³ λ¦¬μ¦/λ°±μ€ 2024. 9. 9. 13:16
μ κ·Όλ°©μ
μ΄μ κ²μκΈ [λ°±μ€] 24262λ²: μκ³ λ¦¬μ¦ μμ - μκ³ λ¦¬μ¦μ μν μκ° 1 (Node.js) μ λ§μ°¬κ°μ§λ‘
μκ³ λ¦¬μ¦μ μκ° λ³΅μ‘λμ λν΄ λ€λ£¨λ κΈ°μ΄λ¬Έμ μ΄λ©° μ μλ μ½λμ μκ°λ³΅μ‘λλ₯Ό λΆμνλ λ¬Έμ μ λλ€.
μκ°λ³΅μ‘λμ λΉ μ€νκΈ°λ²(Big-O)μ λν μ§§μ μ€λͺ κΈμ
μ΄μ κ²μκΈμ μμΌλ νμνμλ©΄ νμΈνμλκ² μ’μ κ² κ°μ΅λλ€π
μ΄λ² λ¬Έμ λν μκ°λ³΅μ‘λμ κ΄ν λ¬Έμ μ΄λ©°, μ λ² κ²μκΈμλ O(1)μ λν λ¬Έμ μμ§λ§
μ΄λ²μλ forλ¬Έμ΄ λ€μ΄κ° O(n)μ λν λ¬Έμ μ λλ€.
νμ΄ β°
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let input = []; rl.on("line", function (line) { input.push(line); }).on("close", function () { // MenOfPassion(A[], n) { // sum <- 0; // for i <- 1 to n // sum <- sum + A[i]; # μ½λ1 // return sum; // } // μ λ ₯κ° let n = Number(input[0]); // n = n^1 console.log(n); // μ΅κ³ μ°¨νμ ^1 => 1 console.log(1); });
λ°±μ€ 24263λ² λ§ν¬
'π μκ³ λ¦¬μ¦ > λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ