LeetCode[JS] > 2718. Sum of Matrix After Queries

2025. 3. 15. 19:45ยท๐Ÿ”’Algorithm

๋ฌธ์ œ๋งํฌ

https://leetcode.com/problems/sum-of-matrix-after-queries/description/

๋ฌธ์ œํ’€์ด

์ด ๋ฌธ์ œ๋ฅผ ์•„๋ฌด ์ƒ๊ฐ์—†์ด ์ˆœ์„œ๋Œ€๋กœ ๊ตฌํ˜„ํ•˜์—ฌ ๋‹ต์„ ๋„์ถœ ์‹œ memory heap size ์ดˆ๊ณผ๋ฅผ ๋งž๋”ฑ๋“œ๋ฆฌ๊ฒŒ ๋œ๋‹ค. 2์ฐจ์› ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด ํ•ด๋‹น ๋ฐฐ์—ด์„ ์กฐ์ž‘ํ•˜๋Š” ๋Œ€์‹  ๋‚˜๋Š” Set ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•˜์—ฌ ์—ฐ์‚ฐํšŸ์ˆ˜๋ฅผ ์ตœ์†Œํ™” ํ•˜์˜€๋‹ค. ๋’ค์— ์žˆ๋Š” ์ฟผ๋ฆฌ์ผ์ˆ˜๋ก ๊ธฐ์กด ๋ฐฐ์—ด์˜ ๊ฐ’์„ override ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋งจ๋’ค์˜ ์ฟผ๋ฆฌ๋ถ€ํ„ฐ ์ˆœํšŒํ•˜๋ฉด์„œ ๊ฐ’์„ ๊ณ„์‚ฐํ•˜๋ฉด ๋œ๋‹ค. 

/**
 * @param {number} n
 * @param {number[][]} queries
 * @return {number}
 */
var matrixSumQueries = function (n, queries) {
    let sum = 0;

    let removedRow = new Set();
    let removedColumn = new Set();

    for (let i = queries.length - 1; i >= 0; --i) {
        let [type, index, val] = queries[i];

        if (type && !removedColumn.has(index)) {
            // 1 -> column
            removedColumn.add(index);
            sum += (n - removedRow.size) * val;
        } else if (!type && !removedRow.has(index)) {
            // 0 -> row
            removedRow.add(index);
            sum += (n - removedColumn.size) * val;
        }
    }

    return sum;
};

 

 

'๐Ÿ”’Algorithm' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

LeetCode [JS] > Third Maximum Number  (0) 2025.03.26
HackerRank > big-sorting  (0) 2025.03.22
LeetCode [JS] > 3192. Minimum Operations to Make Binary Array Elements Equal to One II  (0) 2025.03.12
LeetCode[JS] 53๋ฒˆ Maximum Subarray  (0) 2025.03.11
๋ฐฑ์ค€[JS] > 1697๋ฒˆ ์ˆจ๋ฐ”๊ผญ์งˆ  (0) 2025.03.09
'๐Ÿ”’Algorithm' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
  • LeetCode [JS] > Third Maximum Number
  • HackerRank > big-sorting
  • LeetCode [JS] > 3192. Minimum Operations to Make Binary Array Elements Equal to One II
  • LeetCode[JS] 53๋ฒˆ Maximum Subarray
devWarrior
devWarrior
  • devWarrior
    devWarrior
    devWarrior
  • ์ „์ฒด
    ์˜ค๋Š˜
    ์–ด์ œ
    • ๐ŸงฉDev (263)
      • โญFE (34)
      • ๐Ÿ”’Algorithm (155)
      • โž•Etc. (11)
  • ๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

    • ํ™ˆ
    • ํƒœ๊ทธ
    • ๋ฐฉ๋ช…๋ก
    • ๊ธ€์“ฐ๊ธฐ
    • ๊ด€๋ฆฌ
  • ๋งํฌ

  • ๊ณต์ง€์‚ฌํ•ญ

  • ์ธ๊ธฐ ๊ธ€

  • ํƒœ๊ทธ

    DFS
    ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค
    ์‹ค๋ฒ„4
    ์ฝ”๋”ฉํ…Œ์ŠคํŠธ
    js
    dp
    ๊ตฌํ˜„
    ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ
    BFS
    ์•Œ๊ณ ๋ฆฌ์ฆ˜
    node.js
    Algorithm
    ํ”„๋ก ํŠธ์—”๋“œ
    ์‹ค๋ฒ„1
    ์˜ค๋ธ”์™„
    FE
    javascript
    react
    Lv2
    ์ฝ”ํ…Œ
    nodejs
    leetcode
    ๊ทธ๋ฆฌ๋””
    ์‹ค๋ฒ„2
    ํ‹ฐ์Šคํ† ๋ฆฌ์ฑŒ๋ฆฐ์ง€
    ๊ณจ๋“œ5
    Easy
    ์‹ค๋ฒ„3
    ์ž์Šค
    ๋ฐฑ์ค€
  • ์ตœ๊ทผ ๋Œ“๊ธ€

  • ์ตœ๊ทผ ๊ธ€

  • hELLOยท Designed By์ •์ƒ์šฐ.v4.10.3
devWarrior
LeetCode[JS] > 2718. Sum of Matrix After Queries
์ƒ๋‹จ์œผ๋กœ

ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”